Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

node.js - 在mongodb中删除数组中的项目[重复](Delete an item in array in mongodb [duplicate])

i have a document as

(我有一个文件)

{ "_id" : ObjectId("5de2a0a2336a4c5adc3fc25c"), "image" : { "otherImages" : [ { "imageUrl" : "HL2370207N_1575195338958.jpg", "status" : true }, { "imageUrl" : "HL2370207N_1575195373805.jpg", "status" : true }, { "imageUrl" : "HL2370207N_1575195382992.jpg", "status" : true } ] } }

({“ _id”:ObjectId(“ 5de2a0a2336a4c5adc3fc25c”),“ image”:{“ otherImages”:[{“ imageUrl”:“ HL2370207N_1575195338958.jpg”,“ status”:true},{“ imageUrl”:“ HL2370207N_1575195373805.jpg” ,“ status”:true},{“ imageUrl”:“ HL2370207N_1575195382992.jpg”,“ status”:true}]}})

I have to delete an item of an otherImages array whose imageUrl is "HL2370207N_1575195382992.jpg" $pull cannot applied since it is under node image which is not an array.

(我必须删除其imageUrl为“ HL2370207N_1575195382992.jpg”的otherImages数组的一项,因为它位于不是数组的节点图像下,所以无法应用$ pull。)

please give any guidance .

(请给我任何指导。)

i am new to the mongoDB

(我是mongoDB的新手)

  ask by Bharat Bhurtel translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you can specify the value you want to delete.

(我认为您可以指定要删除的值。)

Like so:

(像这样:)

{ $pull: { <field1>: <value|condition> } }

Source & examples: https://docs.mongodb.com/manual/reference/operator/update/pull/

(来源和示例: https : //docs.mongodb.com/manual/reference/operator/update/pull/)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...