q0987
q0987

Reputation: 35982

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

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} }

Upvotes: 5

Views: 1984

Answers (1)

SomethingOn
SomethingOn

Reputation: 10911

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"

Upvotes: 7

Related Questions