在mongo中使用嵌套元素匹配更新值

时间:2018-10-16 09:28:53

标签: php html mongodb web

我在ehich中有这个mongo结构,我想检查3个分别为_idproduct_type_idcondition_id的值,并且满足所有这些条件的数组的状态应从0至1。

以下是我的mongo数据

{
        "_id" : ObjectId("5b17b991c440782b5a218cd1"),
        "product" : [
                {
                        "id" : ObjectId("5b87d2ef40c1c45f88222093"),
                       	"product_type_id" : ObjectId("5ae8348b7ae0d9538e45ab46"),
                        "condition_id" : [
                                {
                                        "_id" : ObjectId("5ae978187ff1706f3b7dc47c"),
                                        "status" : 1,
                                        "date_added" : "2018-08-30-11-20-15"
                                }
                        ],
                        "shipping_cost" : 100,
                        "date_added" : "2018-08-30-11-20-15",
                        "date_status_change" : "2018-08-30-11-20-15",
                        "status" : 0
                },
                {
                	...
                },
                {
                	...
                }
               ]
}

到目前为止,我已经尝试过了,但是没有用

[
	"_id"=>$merchant_id,
	"product" =>
		[
			'$elemMatch' =>
				[
					'product_type_id' => $product_type_id,
					'condition_id' =>
						[
							'$elemMatch' => 
								[
								 	'_id' => $condition_id,
								]
						]
				]
		],
		'$set' =>
			[
				'product.$.condition_id.$.status' => 1,
			]
]

0 个答案:

没有答案