db.collection.update({_id:"some_id"},{$unset:{"the.nested.key.to.delete":""}});
Is this supported in the mongo node driver? It doesn't seem to work. I tried:
db.collection('my_collection').update({_id:"some_id"},{$unset:{"the.nested.key.to.delete":""}},function(err,result) {
// etc.
});
But that didn't work. I know I could find/retrieve the document, delete the key, then update it... but I'm not a fan of that approach. So is $unset supported, or is there another approach I should be using that I haven't thought of?
Hi Eric,
Using the Node MongoDB driver version 2.2.25, this works for me:
> db.test.find()
{
"_id": 0,
"a": 1,
"b": 2,
"c": 3
}
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost/test', function(err, db) {
db.collection('test').update({'_id': 0}, {'$unset': {'a': ''}}, function(err, res) {
db.close();
});
});
> db.test.find()
{
"_id": 0,
"b": 2,
"c": 3
}
You might be missing quotes on the fields such as _id and $unset.
If it still doesn’t work for you, could you post:
mongod log, within node, etc.Best regards,
Kevin