User Tools

Site Tools


mongodb

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mongodb [2020/04/03 10:24]
jordan 创建
mongodb [2023/03/08 16:09] (current)
xujianglong ↷ Page moved from 内部资料:mongodb to mongodb
Line 1: Line 1:
-## 常用查询+====== MongoDB ======
  
-随机查询几条数据: db.<collection>.aggregate([{$sample:{size:3}}]).pretty()+===== 常用查询 =====
  
-分组计数:db.<collection>.aggregate([{"$group": {_id: "$<field_name>", count:{$sum:1}}}])+**<collection>表示想要查询的集合,如果集合名称是数字,则需要用db['2021-03-01']进行集合查询** 
 + 
 +随机查询几条数据: ''db.<collection>.aggregate([{$sample:{size:3}}]).pretty()'' 
 + 
 +分组计数:''db.<collection>.aggregate([{"$group": {_id: "$<field_name>", count:{$sum:1}}}])'' 
 + 
 +查询最后10条数据:''db.<collection>.find().limit(-10).pretty()'' 
 + 
 +显示数据库:''show databases;'' 
 + 
 +显示集合:''show collections;'' 
 + 
 +显示集合数据量:''db.<collection>.count()''
mongodb.1585880676.txt.gz · Last modified: 2021/02/10 21:29 (external edit)