MongoDb remove subdocument from document

后端 未结 2 1338
挽巷
挽巷 2021-02-07 07:03

I have a collection with a following data:

{

  \"_id\" : ObjectId(\"4e3951905e746b3805000000\"),
  \"m\" : \"hello\",
  \"r\" : [{
      \"_id\" : ObjectId(\"4e         


        
相关标签:
2条回答
  • 2021-02-07 07:16

    It's easy, you just need to use $pull operator:

    db.items.update( {}, 
    { $pull : { r : {"_id": ObjectId("4e39519d5e746bc00f000000")} } }, false, false )
    
    0 讨论(0)
  • 2021-02-07 07:17
    dbh.users.update({"_id": ObjectId("4e39519d5e746bc00f000000")}, {"$unset":{"r":1}},False,False)
    

    Try using unset

    Reference: MongoDB : Update Modifier semantics of "$unset"

    0 讨论(0)
提交回复
热议问题