mongo基本操作

1.安装mongo客户端

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

2.连接mongodb

mongo ip:27017/db_name -u user_name -p

3.创建collection

参考:MongoDB 教程

use xx_db
db.createCollection("xx_collection")

4.插入数据

insert one

use xx_db

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

insert many

db.xx_collection.insertMany(
[
    {
        "id":"200000",
        "time":new Date(),
        "token":"1111111"
    }, {
        "id":"300000",
        "time":new Date(),
        "token":"2222222"
    }
]
)

5.删除数据

delete one

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

delete many

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

6.查看Mongo的collection大小

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

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

7.查看collection是否是sharded

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

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

 

posted @ 2016-03-17 15:11  tonglin0325  阅读(301)  评论(0编辑  收藏  举报