What method is used to unset a key in MongoDB with Waterline ORM?
Consider the following document:
{
name : 'brian',
age : 29
}
Getting the user is no problem:
var users = Users.findOne({ name : 'brian' }).exec(cb);
I would like age to simply go away. I've tried the following to accomplish this:
user.age = undefined;
user.save();
user.age = null;
user.save();
delete user.age;
user.save();
None seem to work. #1 sets it to null, #2 sets it to null, #3 leaves the original value.
Thanks.
Waterline is an ORM meant to support a wide range of datastores, so it doesn't support methods that are particular to just MongoDB. You can always access the underlying MongoDB driver using the .native()
method, then do anything you want (see the MongoDB node driver docs for available methods):
User.native(function(err, collection) {
collection.findAndModify(
{name: 'brian'},
{$unset: {age: true}},
function (err, object) {
// Continue...
}
);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With