当我尝试更新MongoDb集合中的以下文档时,我遇到了问题:
{
"_id" : {
"EDIEL" : "1111",
"StartDate" : {
"DateTime" : ISODate("2016-08-31T22:00:00.000Z"),
"Ticks" : NumberLong(636082776000000000)
}
},
"Versions" : [
{
"Id" : 121031547,
"VersionNumber" : 0,
"Quantity" : 5.58,
"Quality" : "E01",
"Created" : {
"DateTime" : ISODate("2016-09-08T23:49:23.000Z"),
"Ticks" : NumberLong(636089753630000000)
}
},
{
"Id" : 137414738,
"VersionNumber" : 0,
"Quantity" : 19.67,
"Quality" : "E01",
"Created" : {
"DateTime" : ISODate("2016-09-08T23:49:23.000Z"),
"Ticks" : NumberLong(636089753630000000)
}
},
{
"Id" : 121031550,
"VersionNumber" : 1,
"Quantity" : 19.67,
"Quality" : "E01",
"Created" : {
"DateTime" : ISODate("2016-11-15T05:37:38.000Z"),
"Ticks" : NumberLong(636147850580000000)
}
}
],
"MeterId" : 1165,
"OriginalId" : 121031547,
"Unit" : "KWH",
"ReadingFrequency" : "PT15M",
"EndDate" : {
"DateTime" : ISODate("2016-08-31T22:15:00.000Z"),
"Ticks" : NumberLong(636082785000000000)
}
}
我需要在Quantity
数组中使用Id
137414738将版本Versions
更新为25.0。
我的更新查询如下所示:
collection.update(
// query
{
"_id" : {
"EDIEL" : "1111",
"StartDate" : {
"DateTime" : ISODate("2016-08-31T22:00:00.000Z"),
"Ticks" : NumberLong(636082776000000000)
}
}
},
// update
{
$set: { "Versions.1.Quantity": 25.0 }
},
// options
{
"multi" : false, // update only one document
"upsert" : false // insert a new document, if no existing document match the query
}
);
但是,shell输出0记录已更新。
有谁知道我做错了什么? : - )
修改
写入结果如下所示:
"ok" : undefined,
"nInserted" : 0.0,
"nUpserted" : 0.0,
"nMatched" : 0.0,
"nModified" : 0.0,
"nRemoved" : 0.0,
答案 0 :(得分:0)
原来这是Robomongo的一个错误。在正常的cmd shell中工作正常