Py学习  »  MongoDB

MongoDB如何将特定对象从数组移动到另一个数组?

jones • 5 年前 • 1583 次点击  

假设我有以下收藏:

{  
  "_id":ObjectId("562e7c594c12942f08fe4192"),
  "first":[  
    {  
      "shape":"square",
      "color":"blue"
    },
    {  
      "shape":"circle",
      "color":"red"
    }
  ],
  "second": []
}

我想做的是,首先在 first 排列并移动到 second 领域

db.collection.findOneAndUpdate({_id: ObjectId("562e7c594c12942f08fe4192")}, {$pull: {first: {color: "red"}}, $push: {// that specific object to second array}})
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39765
 
1583 次点击  
文章 [ 2 ]  |  最新文章 5 年前