Mongo throwing "Element name 'name' is not valid' exception
In contrast to update
, updateOne
seems to require an update operator;
> db.test.updateOne({name:'alice'},{name:'Alice'})2016-02-16T19:04:07.689+0000 E QUERY [thread1] Error: the update operation document must contain atomic operators> db.test.updateOne({name:'alice'},{$set: {name:'Alice'}}){ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }
...which means your document should probably look like;
var newDocument = new BsonDocument { { "$set", new BsonDocument {"name", "Alice" } } };
...or if you really mean to replace the entire document, use replaceOne
, which should work with your existing documents to replace the entire matching document.