【发布时间】:2020-03-26 05:31:03
【问题描述】:
我有一个文件
{ “_id”:ObjectId(“5de2a0a2336a4c5adc3fc25c”), “图片” : { “其他图像”:[ { "imageUrl" : "HL2370207N_1575195338958.jpg", “状态”:真 }, { "imageUrl" : "HL2370207N_1575195373805.jpg", “状态”:真 }, { "imageUrl" : "HL2370207N_1575195382992.jpg", “状态”:真 } ] } }
我必须删除 otherImages 数组的一项,其 imageUrl 为“HL2370207N_1575195382992.jpg” $pull 无法应用,因为它位于不是数组的节点图像下。请给予任何指导。我是 mongoDB 的新手
【问题讨论】:
-
哼,为什么你觉得
$pull不能申请?你能显示你的查询吗? -
db.userdetails.update( { }, { $pull: { image: {OtherImages: { $elemMatch: { imageUrl: "HL2370207N_1575195382992.jpg" } } } }} 错误是 WriteResult ({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 2, "errmsg" : "Cannot apply $pull to a non-array value" } })