mongodb - mongo中如何在添加一个字段的时候,指定他的字段类型。
天蓬老师
天蓬老师 2017-04-28 09:04:23
0
1
588

比如我想增加一个is_delete 字段,想指定类型为int_32,并且默认值为0.
没有找到好办法
我现在做的是添加这个字段,值为1,然后类型就自动为int_32,然后在批量update为0.
如果直接为0.他显示的是bool false

有没有更简单方法呢。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
洪涛

It doesn’t seem to work, I haven’t seen a way to set it at the database level. For NOSQL like MongoDB, you have to use ORM or business code to deal with this problem.

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

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!