【问题标题】:How to remove an array element in mongodb如何在mongodb中删除数组元素
【发布时间】:2017-07-31 16:27:46
【问题描述】:
productos: [
  {
    name: element 1
    number: 3167518236
    email: "example@gmail.com"
  }
  {
    name: element 2
    number: 3167518236
    email: "example@gmail.com"
  }
{
    name: element 3
    number: 3167518236
    email: "example@gmail.com"
  }
]

例如,我怎样才能删除名称:element2 编号:3167518239 和电子邮件:example@gmail.com 的数组 2

我正在使用它,但它不起作用!

db.list.update({},{"$unset":{productos:{name:"element 2"}}})

【问题讨论】:

标签: mongodb database


【解决方案1】:

在 mongodb 中从数组中删除元素是使用 the $pull operator 完成的。

对于您的特定情况,您可以使用 {name:"element 2"} 作为拉取规范中的查询。

【讨论】:

  • db.usuarios.update({},{"$pull":{productos:{nombre:"element 2"}}}) 仍然无法正常工作!
猜你喜欢
  • 2013-06-02
  • 2020-04-16
  • 2016-02-25
  • 1970-01-01
相关资源
最近更新 更多