I have a collection with an array field. I have code to update a single document in this collection. The update needs to remove a single element from the array field and I use $pull. I expect Meteor’s Mongo.Collection.update to return 0, if the array element I specify does not exist in the specified document, but instead I see it returns one.
I issue the same command in mongo shell and do see the expected WriteResult.nModified.
Mongo shell - assume the referenced cars document does NOT have ‘foobar’ in it’s fileIds array property.
meteor:PRIMARY> print(db.cars.update({ _id: 'K9RKyTCzaAp4YipEF' }, { $pull: {fileIds: 'foobar'} }));
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
Same thing, done on Meteor server-side always returns me 1.
var nModified = Cars.update(this.id, {
$pull: { fileIds: 'foobar' }
});
logger.info("Removed file count", nModified); >>>>>> Always returns 1
I’m not using SimpleSchema for this collection, although I’m using it for some other collections.
Thanks Rags