How to specify the field type when adding a field in mongo.

  mongodb, question

For example, I want to add oneis_deleteField, want to specify the type isint_32And the default value is0.
No good solution was found.
What I’m doing now is adding this field with a value of1, then the type is automaticallyint_32, and then in bulkupdatE is0.
If it is 0 directly, what he shows isbool false

There is no simpler way.

It seems that this is not possible. I have never seen a method set at the database level. For NOSQL such as MongoDB, ORM or business code has to be used to deal with this problem.

As for what you said, it shows bool false after update, shouldn’t it?

> db.test.save({'a':1,'b':1})
 WriteResult({ "nInserted" : 1 })
 > db.test.find()
 { "_id" : ObjectId("5625f1d9d782d26c6536ee8c"), "a" : 1, "b" : 1 }
 > db.test.update({'a':1},{'$set':{'b':0}})
 WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
 > db.test.find({'a':1})
 { "_id" : ObjectId("5625f1d9d782d26c6536ee8c"), "a" : 1, "b" : 0 }
 >

Isn’t this still 0?