mongoDB常用执行语句

插入数据操作

插入一条数据

db.getCollection('user').insert({
    "name" : "zhangSan",
    "age" : NumberInt(24)
});

 插入多条数据

db.getCollection('user').insertMany([
{
    "name" : "zhangSan",
    "age" : NumberInt(24)
},
{
    "name" : "liSi",
    "age" : NumberInt(24)
}]);

更新数据操作

实现更新一个字段的值为另一个字段的值

db.getCollection('User').find({"id":"289732258753679678"}).forEach(function(item){
    db.getCollection('User').update({"id":item.id},{"$set":{"firstName":item.lastName}},false,true);
});

 

posted @ 2019-02-27 14:20  FreeFall  阅读(1211)  评论(0编辑  收藏  举报