为什么Mongoid不将boolean保存为true或false?(Why Mongoid doesn't save boolean as true or false?)

编程入门 行业动态 更新时间:2024-10-23 14:20:55
为什么Mongoid不将boolean保存为true或false?(Why Mongoid doesn't save boolean as true or false?)

我有一个带有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

更多推荐

本文发布于:2023-04-28 01:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1330274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:保存为   不将   boolean   Mongoid   false

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!