The database schema:
{
_id: "kun2",
result150160: [10,20,30];
moon: 4
}
I want to delete the whole field result150160 by the client with a variable:
var deleteresult = "result150160"
Box.update( {_id: this._id} , {$unset: { deleteresult } } );
Press CTRL+A on your keyboard to select all the text within the document. Right-click, then click Toggle Field Codes. Press CTRL+SHIFT+F9 on your keyboard. This will remove the field codes, replacing them with the text they contained.
In the Navigation Pane, right-click the table, and then click Design View. In the table design grid, select the field that you want to delete, and then press DEL.
In MongoDB, you can use the $unset field update operator to completely remove a field from a document. The $unset operator is designed specifically to delete a field and its value from the document.
Try this it should work for you:
var deleteresult = "result150160";
var updateQuery={$unset:{}};
updateQuery.$unset[deleteresult]=1;
Box.update( {_id: this._id} ,updateQuery,false,true);
The correct syntax is this:
Box.update( {_id: this._id} , {$unset: { deleteresult : "" } } );
You have to specify a value for the $unset
operation : { deleteresult : "" }
. Even if it is empty.
Checkout the relevant docs:
db.collection.update( { field: value1 }, { $unset: { field1: "" } } );
The above example deletes field1 in collection from documents where field has a value of value1. The value of the field in the $unset statement (i.e. "" above) does not impact the operation.
You could do:
var deleteresult = {};
deleteresult["result150160"] = true
Box.update( {_id: this._id} , {$unset: deleteresult } );
Basically you have to use a key value pair, it doesn't matter what you use for true
, as long as theres something there.
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