mongo 常用操作

删除字段

db.matchconfs.update({},{$unset:{used:""}},false,true)

 

添加字段

db.matchconfs.update({},{$set:{used:0}},false,true)

 

更加某个字段更新另一个字段

db.masterscorenews.update({uid:1111},[{ $set:{ bak:"$age" } }])

 

 查询

db.quweimodels.find({ uri:{$regex:/\/identity_number\//} }, {err:1, uri:1, "reqArgs.body":1,body:1})

 

// 新增字段,idtype, 内容为$id[:12]
db.matchconfs.aggregate(
   [

     {
        $set:
        {
          idtype: { $substr: [ "$id", 0, 12 ] },
        }
    },
    {
        $out:"matchconfs"
    }
    ]
);
// 选出不同的idtype
db.matchconfs.aggregate([
{
    $facet:{
        "selectAB":[
            {$match:{type:{$gte:3}}},
            {$group:{_id:{$substr:["$id",0,12]}}},
        ],
        
        "selectTaotai":[
            {$match:{type:1}},
            {$group:{_id: {$substr:["$promote_match",0,12]}  }},
        ]
    }
},
{
    $unwind:
      {
        path: "$selectAB",// 所有复式赛类型
      }
},
{
    $project:{
        _id:"$selectAB._id",
        isBind:{
           $in:["$selectAB._id","$selectTaotai._id"]
        }
    }
},
{
    $out:"fushitypes"
}
])

 

posted @ 2019-12-11 11:12  浪浪辛  阅读(181)  评论(0)    收藏  举报