MongoDB, remove object from array

前端 未结 7 2087
余生分开走
余生分开走 2020-11-22 16:19

Doc:

{
   _id: 5150a1199fac0e6910000002,
   name: \'some name,
   items: [{
      id: 23,
      name: \'item name 23\'
   },{
      id: 24,
      name: \'ite         


        
相关标签:
7条回答
  • 2020-11-22 17:19

    For a single record in array:

    db.getCollection('documents').update(
        { },
        {'$pull':{ 'items':{'mobile': 1234567890 }}},
        {new:true}
    );
    

    For a multiple records with same mobile number in array:

    db.getCollection('documents').update(
        { },
        {'$pull':{ 'items':{'mobile': 1234567890 }}},
        {new:true,multi:true}
    )
    
    0 讨论(0)
提交回复
热议问题