MongoDB嵌套文档中无法取消$ unset字段

时间:2018-02-15 10:50:38

标签: mongodb pymongo pymongo-3.x

我的文档如下所示

{
  "list" :{
    "friends": [
        {
        "Name": "John",
        "Contact": "xyz",
        "Code": "B"
        },
        {
        "Name": "Smith",
        "Contact": "abc",
        "Code": "A"
        }
      ]
   }
}

我尝试使用基于过滤器的$unset运算符删除字段。我的代码如下:

result = db.collection.update_many({"list.friends.code": "A"}, 
         {"$unset": {"list.friends.$.Name": "", "list.frieds.$.Contact": ""}})

但是,我得到pymongo.errors.WriteError: Invalid BSON field name 'list.friends.$.Name'

1 个答案:

答案 0 :(得分:1)

请改为尝试:

var ExtractTextPlugin = require("extract-text-webpack-plugin");


module.exports = {
    entry   :   './src/app.js',
    output  :   {
        filename    :   './dist/bundle.js'
    },
    module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader','sass-loader']
        })
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin({
        filename : 'app.bundle.css'
    }),
  ]
}