Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 1 mean in { $unset : { field : 1} }

Tags:

mongodb

In the following snippet, I am able to remove two key fields from a collection with different parameters (i.e. One is 1 and the other is 0).

> i = { name : 'name', age : 25, gender : 'female' };
{ "name" : "name", "age" : 25, "gender" : "female" }
> db.users.insert(i)
> db.users.find()
{ "_id" : ObjectId("4e8b5b5e654f46ccc304e44e"), 
  "name" : "name", "age" : 25, "gender" : "female" }
> db.users.update({ name : 'name'}, 
                  {$unset : {age : 1, gender : 0}}) // check here
> db.users.find()
{ "_id" : ObjectId("4e8b5b5e654f46ccc304e44e"), "name" : "name" }
> 

Reference: MongoDB $unset

Question> What is the usage of 1 in the following manual?

{ $unset : { field : 1} }

like image 452
q0987 Avatar asked Oct 04 '11 19:10

q0987


1 Answers

As far as I know, this is simply due to JSON/BSON syntax. There has to be a value, but it doesn't matter what the value is. In the MondoDB documentation they typically use 1.

MongoDB : Update Modifier semantics of "$unset"

like image 68
SomethingOn Avatar answered Sep 28 '22 00:09

SomethingOn