Mongodb批量修改、查询

1、批量修改某个字段某种数据类型(将string型($type=2)的id字段改为int64型)

//string修改为长整型
db.getCollection('XXXXX').find({"id" : {$type : 2}}).forEach(function(x){
    x.id=new NumberLong(x.id);
    db.getCollection('XXXXX').save(x);
});

2、批量添加或修改字段

db.getCollection('XXXX').update({},{$set:{'字段名':NumberInt(0)}},{multi:true});

3、查询只在A表但是不在B表中的数据

 db.getCollection('XXA').aggregate([{$lookup:{"from": XXB, "localField": “A中字段”, "foreignField": "B中字段”, "as": “取个名字C”}},{$match:{“C”: {"$size": 0}}}]);

猜你喜欢

转载自blog.csdn.net/qq_37575994/article/details/128235844