当我在 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
]
}
]
}
我运行此代码的目标是将使用类型从 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