How to replace all the elements of an array in a MongoDB document?
This should be a straight forward update.
Posts.update({user: userVar}, {$set: { tags: arr }});
In mongo
> db.so34562815.find( ).pretty(){ "_id" : ObjectId("56875d7a6a21dd6b99743439"), "user" : "test", "tags" : [ "one", "two" ]}> arr = ['three'][ "three" ]> db.so34562815.update({user:'test'},{$set: {tags:arr}})WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.so34562815.find( ).pretty(){ "_id" : ObjectId("56875d7a6a21dd6b99743439"), "user" : "test", "tags" : [ "three" ]}