简体   繁体   English

MongoDB Compass如何处理int64?

[英]How does MongoDB Compass deal with int64?

I have read the official documentation about int64 and I need use NumberLong wrapper the int64. 我已经阅读了有关int64的官方文档,我需要在int64中使用NumberLong包装器。 But I find there is some special values could be used without NumberLong: 但是我发现没有NumberLong可以使用一些特殊值: 在此处输入图片说明

In my image, I think the MongoDB Compass will treat 1128505640310804481 as double just like Javascript and use the round 1128505640310804500(this is what I get from Javascript). 在我的图像中,我认为MongoDB Compass会将1128505640310804481像Javascript一样对待,并使用回合1128505640310804500(这是我从Javascript得到的)。 The data in DB is shown in int64 so I think the 1128505640310804481 is stored correctly as int64. DB中的数据显示在int64中,因此我认为1128505640310804481正确存储为int64。 Since 1128505640310804500 is not equal to 1128505640310804481, I think I should find no data matched my filter, but MongoDB Compass give me the result. 由于1128505640310804500不等于1128505640310804481,我想我应该找不到匹配我的过滤器的数据,但是MongoDB Compass给出了结果。

So my question is: when I enter int64 in MongoDB Compass Filter like the picture, how does it deal with the int64 and why it could match the correct int64 data stored in DB? 所以我的问题是:当我如图所示在MongoDB Compass Filter中输入int64时,它如何处理int64以及为什么它可以匹配存储在数据库中的正确int64数据?

when I enter int64 in MongoDB Compass Filter like the picture, how does it deal with the int64 and why it could match the correct int64 data stored in DB? 当我如图所示在MongoDB Compass Filter中输入int64时,它如何处理int64?为什么它可以匹配存储在数据库中的正确int64数据?

To start with, MongoDB can store 64-bit integer value because data are stored as BSON (binary serialisation format). 首先,MongoDB可以存储64位整数值,因为数据以BSON(二进制序列化格式)存储。 This solves the issue in the server. 这样可以解决服务器中的问题。 See also BSON Types . 另请参阅BSON类型

Now, for MongoDB Compass it is able to identify the type of number (int32, int64, or Double) by auto-casting. 现在,对于MongoDB Compass,它可以通过自动广播识别数字的类型(int32,int64或Double)。 It detects the value in the editor, when an int32 is edited to a value over 32 bits AND the value passes the +/- of Number.isSafeInteger then it casts to int64 . 当将int32编辑为超过32位的值并且该值通过Number.isSafeInteger的+/-时, 它将在编辑器中检测到该值,并将其转换为int64

Part of MongoDB Compass that does the type checking is actually has been open-sourced. 实际上,进行类型检查的MongoDB Compass的一部分已开源。 See the type checker code: mongodb-js/hadron-type-checker/blob/master/src/type-checker.js . 请参阅类型检查器代码: mongodb-js / hadron-type-checker / blob / master / src / type-checker.js The NPM package is hadron-type-checker . NPM软件包是hadron-type-checker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM