Answer the question
In order to leave comments, you need to log in
Is there an update query in mongo db such that if there is a record in the database, then update it, if it does not exist, then create a new record in the collection?
The bottom line is, I add data in a cycle
for(var i = 0; i<arrAll.length; i++){
db.get().collection('bookEntries').insert({
id: arrAll[i].id,
author: arrAll[i].author,
authorLink: arrAll[i].authorLink,
authorThumb: arrAll[i].authorThumb,
})
}
Answer the question
In order to leave comments, you need to log in
https://docs.mongodb.com/manual/reference/method/d...
The update method with the upsert=True argument updates an existing document or creates a new one if it didn't exist.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question