我有一个带有RoR和Mongoid的应用程序,我在Document中有一个布尔字段。 但是当我保存文档并看到mongo时,它返回0或1。
为什么mongoid不保存真假? 有什么理由吗?
我试图在mongoid的文档中找到它,但没有成功...
I have an app with RoR and Mongoid, and I have a Boolean field in a Document. But when I save the document and see the mongo, it return 0 or 1.
Why mongoid don't save true or false? There's any reason?
I try to find it on documentation of mongoid, but don't have success...
最满意答案
真值和假值在BSON规范上为“\ x00”和“\ x01”,因为mongoid使用BSON协议将对象传递给mongodb,true和false转换为0和1.您可以在这里看到代码https ://github.com/mongodb/bson-ruby/blob/master/lib/bson/true_class.rb#L25
True and False values are on the BSON spec as "\x00" and "\x01", as mongoid passes the objects to mongodb using the BSON protocol, true and false are converted to 0 and 1. You can see the code in here https://github.com/mongodb/bson-ruby/blob/master/lib/bson/true_class.rb#L25
更多推荐
发布评论