0

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 } ] } }

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. please give any guidance . i am new to the mongoDB

2
  • 1
    Hum, why do you think $pull cannot be applied? Could you show your query? Commented Dec 1, 2019 at 10:53
  • db.userdetails.update( { }, { $pull: { image: {OtherImages: { $elemMatch: { imageUrl: "HL2370207N_1575195382992.jpg" } } } }} ) and the error is WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 2, "errmsg" : "Cannot apply $pull to a non-array value" } }) Commented Dec 1, 2019 at 11:00

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.