Cyra
Cyra

Reputation: 75

mongoDB - Delete a document which is an object

I would like to delete the document displayed on the image but this document is an object ("{}"), how can I delete it? thank you !

https://zupimages.net/up/20/18/jdfq.png

Upvotes: 0

Views: 30

Answers (1)

Tom Slabbaert
Tom Slabbaert

Reputation: 22276

I'm not sure if I understood correctly but it seems like you want to use $unset

db.collection.updateOne({_id: documentID}, {$unset: {"modules.SHOPECO.test": ""}})

This will remove the field test from the modules.SHOPECO object from the specific document, you want also use updateMany instead of updateOne if you want this to happen on multiple documents.

Upvotes: 1

Related Questions