I'm trying to figure out how to update a collection in my MongoDB. Basically, I want to take a list of email addresses, check if they exist in the DB, and if they don't, create a new User from them, all in the same query. Is this possible?
Right now I'm doing this:
const usersWithEmailsOnly = [<array-of-emails];
User.update({
email: {
$in: usersWithEmailsOnly.map(userWithEmail => userWithEmail.email),
},
}, { multi: true, upsert: true }).exec()
And I get this response back from the server:
{ ok: 0, n: 0, nModified: 0 }
And when I look at the DB, I see that no users are created. Is there something else I need to be doing?