美文网首页
Mong查询语法 Group Aggregate Match R

Mong查询语法 Group Aggregate Match R

作者: 醉酒的姑娘 | 来源:发表于2021-03-03 14:01 被阅读0次

工具:Robo
添加Covertotal字段


image.png

查看添加完后的数据


image.png

参数说明:

query : update的查询条件,类似sql update查询内where后面的。
update : update的对象和一些更新的操作符(如,inc...)等,也可以理解为sql update查询内set后面的
upsert : 可选,这个参数的意思是,如果不存在update的记录,是否插入objNew,true为插入,默认是false,不插入。
multi : 可选,mongodb 默认是false,只更新找到的第一条记录,如果这个参数为true,就把按条件查出来多条记录全部更新。
writeConcern :可选,抛出异常的级别。

1 、添加一个字段. table 代表表名 , 添加字段 content,字符串类型

db.table.update({}, {$set: {covertotal:""}}, {multi: true})

2、删除一个字段

db.table.update({},{$unset:{covertotal:""}},false, true)

3、查询memberid为null的数据

db.getCollection('MemberBrowsing').find({"MemberId":null})

4、删除memberid为null的数据

db.getCollection('MemberBrowsing').remove({"MemberId":null})

5、更新字段 更新不等于空数组的ForbiddenLevel字段值为空数组

db.getCollection('EquipmentInfo').update({"ForbiddenLevel" : {$ne:[]}},{$set:{"ForbiddenLevel" : []}}, {multi: true})

6、更新表A的中的字段Area的内容http替换为https

    db.getCollection('A').find({Area:/http:\/\//}).forEach(
   function(item){         
   a = item.Area.replace(/http:\/\//i, "https://");
   db.getCollection('A').update({"_id":item._id},{$set:{"Area": a}})
   }
)

7、查询content为“aaa”的所有记录中,共有多少个不重复的author的记录数

var b=
db.getCollection('A').aggregate([
{$match:{"content" : "aaa"}},
{
    $group:{
        _id:"$author",
        count:{$sum:1}
        }
  }
  ])

b.itcount();

8、模糊查询 查询Content字段 包含“key”的所有记录

    db.getCollection('A').find({"Content" : {"$regex":"key"}})

相关文章

  • Mong查询语法 Group Aggregate Match R

    工具:Robo添加Covertotal字段 查看添加完后的数据 参数说明: query : update的查询条件...

  • 聚合查询

    db.message.aggregate([ {$match:{"列":"值"}}, {$group:{_id:"...

  • MongoDB聚合aggregate

    数据准备 $group 查询每个职位的总工资:db.emps.aggregate([{"$group":{_id:...

  • Mongodb 的高级查询

    关键词:mongodb, mongo, project, group, aggregate, 聚合管道, 高级查询...

  • mongo回顾(八:聚合查询二)

    上一篇简单的介绍了mongo的聚合查询,并举例了match与lookup的使用,今天的话继续介绍聚合查询与Mong...

  • Elasticsearch查询语法

    查询语法 match all query define query number term query bool ...

  • 文档的所属用户

    作用:更改文档的所属用户 语法:#chown -R username文档路径 语法:#chgrp -R group...

  • SCAN迭代器

    语法 SCAN cursor [MATCH pattern] [COUNT count] 通过类似 分页查询的方式...

  • 2021-11-01

    GraphQL db.groups.aggregate([ // {$match: {"_id": ObjectI...

  • neo4j查询语言

    查询整个数据库: match(n) return n; 删除所有关系和节点: MATCH (n)-[r]-()DE...

网友评论

      本文标题:Mong查询语法 Group Aggregate Match R

      本文链接:https://www.haomeiwen.com/subject/smuqqltx.html