You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was expecting the 2nd argument to the callback to be the newly created or updated doc, but there is no 2nd argument:
I'm coming from nedb which supposedly has same API so this is probably wrong:
db.things.update({ hash: data.hash }, data, { upsert: true })
.then((err, numReplaced, doc) => {
if (numReplaced) {
return console.log('replaced %s docs', numReplaced);
}
// how do i get num of docs updated and also the new docs?
console.log(doc);
})
.catch(err => {
return console.error(err, data);
});
But I want to get number of docs replaced (if upserted) and also the new doc regardless of update or insert happened.
The text was updated successfully, but these errors were encountered:
First as you use promises and mongojs does not support promises out of the box I guess you opened this issue in the wrong repository (did you mean the official mongodb driver?)
The write result you'll receive in a callback as second argument looks somehow like this
{ n: 1,
nModified: 0,
upserted: [ { index: 0, _id: abeabeabeabeabeabeabeabe } ],
ok: 1 }
You can use the _id value of the upserted array to query the documents after updating the db.
I was expecting the 2nd argument to the callback to be the newly created or updated doc, but there is no 2nd argument:
I'm coming from nedb which supposedly has same API so this is probably wrong:
But I want to get number of docs replaced (if upserted) and also the new doc regardless of update or insert happened.
The text was updated successfully, but these errors were encountered: