插入数据操作

插入一条数据

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);
});

 

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2021-07-22
  • 2021-09-18
  • 2021-11-20
  • 2022-12-23
  • 2021-06-14
猜你喜欢
  • 2021-10-24
  • 2021-10-12
  • 2022-12-23
  • 2022-01-15
  • 2021-06-26
  • 2021-11-26
  • 2022-12-23
相关资源
相似解决方案