当我在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