tonglin0325的个人主页

mongo基本操作

1.安装mongo客户端#

参考:ubuntu安装mongodb-4.4(通过apt命令)

2.连接mongodb#

1
mongo ip:27017/db_name -u user_name -p

3.创建collection#

参考:MongoDB 教程

1
2
use xx_db
db.createCollection("xx_collection")

4.插入数据#

insert one

1
2
3
4
5
6
7
8
9
10
use xx_db

db.xx_collection.insertOne(
{
"id":"100000",
"time":new Date(),
"abc":"123456"
}
)

insert many

1
2
3
4
5
6
7
8
9
10
11
12
13
db.xx_collection.insertMany(
[
{
"id":"200000",
"time":new Date(),
"token":"1111111"
}, {
"id":"300000",
"time":new Date(),
"token":"2222222"
}
]
)

5.删除数据#

delete one

1
2
3
use xx_db
db.xx_collection.deleteOne({'id':'200000'})

delete many

1
2
db.xx_collection.deleteMany({'token':'1111111'})

6.查看Mongo的collection大小#

1
2
db.getCollection("your_collection").stats()

参考:获取mongo 数据大小及collection大小

7.查看collection是否是sharded#

1
2
db.getCollection("your_collection").stats()

没有sharded字段,或者sharded值为false,都不是sharded collection