For reference only, in node.js using Mongoose 3.6:
model.update( findquery, updatequery, { upsert: true }, function(err, numberAffected, rawResponse) { ... });
If rawResponse looks like this when it updated an existing document:
{ updatedExisting: true, n: 1, connectionId: 222, err: null, ok: 1 }
And he looks like this when he created a new document:
{ updatedExisting: false, upserted: 51eebc080eb3e2208a630d8e, n: 1, connectionId: 222, err: null,
(Both cases return numberAffected = 1)
superiggy Jul 23 '13 at 17:27 2013-07-23 17:27
source share