MongoDB从int32转换为double本身

时间:2018-04-02 11:40:02

标签: javascript mongodb casting mongo-shell studio3t

当我在shell中运行mongoDB时,我遇到了一个奇怪的问题。 我的集合结构如下mongoDB中所示.ServiceList项的类型必须是整数。

{ 
    "_id" : ObjectId("56565"), 
    "Contact" : "", 
    "Email" : "", 
    "AppList" : [

        {
            "Code" : "", 
            "Usage" : NumberInt(542),    
            "LicenceType" : "Monthly", 
            "CreatedDate" : ISODate("2015-07-29T06:15:20.520+0300"), 
            "ServiceList" : [
                1,5,8
            ]

        }
    ]

}

我的目标是运行此代码将Usage类型从int32转换为int64。它运行正常。当我运行下面的代码时。奇怪的事情,AppList.ServiceList内的项目类型从double本身转换为int32

db.CustomerInfo.find({}).forEach( function (item) {
 if(item.AppList != undefined){

   item.AppList.forEach(function (x){
      x.Usage = NumberLong(x.Usage);

    });
           db.CustomerInfo.save(item);
 }
});

似乎是这样,

{ 
    "_id" : ObjectId("56565"), 
    "Contact" : "", 
    "Email" : "", 
    "AppList" : [

        {
            "Code" : "", 
            "Usage" : NumberLong(542),    
            "LicenceType" : "Monthly", 
            "CreatedDate" : ISODate("2015-07-29T06:15:20.520+0300"), 
            "ServiceList" : [
                1.0,5.0,8.0
            ]

        }
    ]
}

我该如何解决这个问题?

MongoDB版本:3.4.9 MongoShell版本:v3.4.9

0 个答案:

没有答案