我在mongodb的collection中具有以下值。现在,我想获取数组single
为status
和1
为transferred
的数组内的0
字段。但是我也想在同一查询中将set
transferred
到1
,这样我就不必编写多个查询。
以下是我的收藏
{
"_id" : ObjectId("5b5c268af93afb77f9d904db"),
"vendor_id" : ObjectId("5b17b991c440782b5a218cd1"),
"single" : [
{
"product_id" : ObjectId("5af5619d977f8723188a8f81"),
"product_type_id" : ObjectId("5ae834807ae0d9538e45ab45"),
"condition_id" : ObjectId("5ae978587ff1706f3b7dc47e"),
"selling_price" : 100,
"quantity" : "27",
"shipping" : "44",
"date_added" : "2018-07-28-08-17-14",
"date_live" : 0,
"status" : 1,
"flag" : 0,
"transferred" : 0
},
{
"product_id" : ObjectId("5af2bd44a003533a8abf4e56"),
"product_type_id" : ObjectId("5ae834807ae0d9538e45ab45"),
"condition_id" : ObjectId("5ae978187ff1706f3b7dc47c"),
"selling_price" : 200,
"quantity" : 403,
"shipping" : 702,
"date_added" : "2018-08-21-10-39-47",
"date_live" : 1,
"status" : 1,
"flag" : 0,
"transferred" : 0
},
{
"product_id" : ObjectId("5af2bd44a003533a8abf4e56"),
"product_type_id" : ObjectId("5ae834807ae0d9538e45ab45"),
"condition_id" : ObjectId("5ae977da7ff1706f3b7dc47a"),
"selling_price" : 100,
"quantity" : 809,
"shipping" : 11,
"date_added" : "2018-09-04-13-44-10",
"date_live" : 0,
"status" : 0,
"flag" : 0,
"transferred" : 0
}
]
}
到目前为止,我已经写了这篇文章
$pipeline=[
[
'$match'=>
[
'vendor_id'=>$vendor_id,
'single.status'=>1,
'single.transferred'=>0
]
],
[
'$project'=>
[
'single'=>1
]
]
];
但是我无法set
将转移的值设为1