【发布时间】:2016-07-24 11:26:40
【问题描述】:
我正在尝试在 MongoDB 上运行带有 not in clase 的更新子查询样式,但它不起作用。我相信这是因为toArray 将ObjectIds 转换为文本而不是将其保留为DBRef。以下是我的代码:
var items = db.listsProducts.find({_id: {$exists: true}}, {product: true, _id: false}).toArray();
db.products.update({_id: {$nin: items}}, {$set: {'status':'inactive'}},{multi:true});
'product' 是 listProducts 集合中的 DBRef 字段。 'products' 是我要更新的集合。
它不会更新不在“项目”中的字段,而是更新所有文档。
我做错了什么?谢谢。
列表产品:
{
"_id" : ObjectId("54e4bf7bade0276f008b4567"),
"__type" : "Core\Libs\Listing\Entity\Product",
"type" : "inventoryItem",
"产品" : DBRef("产品", ObjectId("54e308e23b8e778d128b4799")),
“列表”:DBRef(“列表”,ObjectId(“54e4aeab5252416c008b4569”)),
“库存数据”:{
"__type" : "Core\Libs\Listing\Entity\Product\InventoryData",
"parLevel" : NumberLong(0),
"itemsOnHand" : NumberLong(0)
},
“时间日志”:{
"__type" : "Core\Utils\Entity\TimeLog",
"createdAt" : ISODate("2015-02-18T16:36:11.387+0000"),
"updatedAt" : ISODate("2015-07-07T07:31:25.900+0000"),
“deletedAt”:空
}
}
产品:
{
"_id" : ObjectId("54e308d83b8e778d128b4588"),
“__type”:“核心\库\产品\实体\产品”,
"名称" : "胡萝卜片",
“gtin”:“10071179184300”,
“状态”:“活动”,
"defaultPrice" : NumberLong(0),
“参考”:{
"__type" : "Core\Libs\Product\Entity\Product\References",
"制造商" : DBRef("制造商", ObjectId("54e308d73b8e778d128b4569")),
"类别" : DBRef("1ws-categories", ObjectId("53e1e8723b8e77a52b8b45fd"))
},
“信息”:{
"__type" : "核心\库\产品\实体\产品\信息",
“描述”:{
"__type" : "Core\Libs\Product\Entity\Product\Description",
"short" : "Carrot Smooth Sli 1/20#",
"long" : "Simplot Classic - Carrot Smooth Sli 1/20#"
},
“属性”:{
"__type" : "Xeeo\Services\Core\Abstracts\Collection",
“实体”:[
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "品牌名称",
“价值”:“Simplot 经典”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "制造商 GLN",
“价值”:“0071179000009”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "制造商名称",
“价值”:“J. R. Simplot 公司”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "原产国",
“价值”:“美国”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "最后修改日期",
“价值”:“2014-12-03T09:42:04”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "出版日期",
“价值”:“2011-10-26T00:00:00”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "开始可用日期",
“价值”:“2014-12-03T00:00:00”
},
{
"__type" : "Core\Utils\Entities\KeyValuePair",
"key" : "深度 (IN)",
“价值”:“13.375”
}
]
}
},
"图片" : "http://www.fsenetportal.com/FSENetimages.nsf/0/BB29958620D9515A87257AA6005068B1/$file/10071179184300_A1CD.jpg?OpenElement",
"elasticSearchIndexStatus" : "索引",
“时间日志”:{
"__type" : "Core\Utils\Entity\TimeLog",
"createdAt" : ISODate("2015-02-17T09:24:40.138+0000"),
"updatedAt" : ISODate("2016-03-25T00:56:21.219+0000"),
“deletedAt”:空
}
}
【问题讨论】:
标签: mongodb