1

我正在尝试"virtualNumber" : "12345"在以下文档中删除:

{
"_id" : ObjectId("50a9db5bdc7a04df06000005"),
"billingInfo" : null,
"date" : "dsfdsfsdfsd",
"description" : "sdfsdff",
"pbx" : {
  "_id" : ObjectId("50a9db5bdc7a04df06000006"),
  "did" : {
    "1234567890" : {
      "inventoryId" : "509df7547e84b25e18000001",
      "didcountry" : "india",
      "didState" : "bangalore",
      "routeType" : "CallForward",
      "didNumber" : "1234567890",
      "didVirtualNumbers" : [
        {
          "virtualNumber" : "12345"
        },
        {
          "virtualNumber" : "56789"
        }
      ],
      "id" : ObjectId("50a9db9acdfb4f9217000002")
    }
  },
},

我正在使用 node.js,所以我在 JavaScript 中构造了一个查询:

var query = {_id: ObjectId("50a9db5bdc7a04df06000005")};

var obj = {};
obj["pbx.did.1234567890.didVirtualNumbers.virtualNumber"]=12345;
//problem
collection.update(query,{$pull:obj});
4

2 回答 2

2

您需要匹配数组元素,例如:

{"$pull": {"pbx.did.7259591220.didVirtualNumbers": {"virtualNumber": "12345"}}}

因此,您应该将代码更改为:

obj["pbx.did.7259591220.didVirtualNumbers"]={"virtualNumber": "12345"};
于 2012-11-19T07:47:30.490 回答
0

请参考http://www.mongodb.org/display/DOCS/Updating#Updating-%24pull

它提到拉字段应该是一个数组。

于 2012-11-19T07:40:25.223 回答