It depends on the use case. If you want to receive an handle an error if the index already exists I would use collection.ensureIndex(); if you want to clobber the data use $set if you want to update data use set the upsert flag.
yes here is my repo https://github.com/Ceci007/vidly-backend the problem is in the movies.js router, all started to crash when I tried to add image upload functionality for this I changed the movie.js model and the movies.js router and now my app is not working, I tried postman and get, post and put have errors, they have trouble with the movieImg: req.file.path that’s what I’m getting. I’ll wait patiently if someone could help me this weekend please.
ok so right now what I have is the node server running with your cloned repository…
$ nodemon index.js
[nodemon] 1.18.11
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
info: Listening on port 3900...
info: Connected to mongodb://localhost/vidly...
Mongodb is listening on 27017
2019-08-23T10:16:39.600-0500 I NETWORK [initandlisten] waiting for connections on port 27017
I have a DB named ‘vidly’ and a table named ‘users’.
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
vidly 0.000GB
> use vidly
switched to db vidly
> show tables
users