Is there a more efficient way to achieve the same functionality in JavaScript?
I have to find a user, validate their password, and then update their document. Can I optimize this process by reusing the already retrieved document (stored in var doc) for updating? Or should I stick to the current approach of searching for the user again by name during the update operation.
user_collection.findOne({ name:name }, function(err, doc) {
if(err)
throw err;
if(doc) {
// verify doc.password etc
user_collection.update({ name:name }, {$set: { last_joined:last_joined }}, { upsert:true }, function(err, doc) {
if(err) {
// log error
}
});
}
});