MongoDB 常用命令

create DB
use newDBname;

create collection
db.newCollectionName.insert({m:"test"});

query by time
db.DOL_LIVE.find({t:{'$gte':'2011-01-01 09:32:42,485','$lte':'2012-01-01 09:32:42,485'}});

query by like "%str%"
db.DOL_LIVE.find({m:{'$regex':'.*str.*'}});

remove by time
db.DOL_LIVE.remove({t:{'$gte':'2011-01-01 09:32:42,485','$lte':'2012-01-01 09:32:42,485'}})

find most recent records(skip most records);
db.DOL_LIVE.find().count()
db.DOL_LIVE.find().skip(10000).limit(5)

Create a Capped Collection (To create a capped collection limited to 40 KB)
db.createCollection("mycoll", {capped:true, size:40*1024})

Convert a Collection to Capped
db.runCommand({"convertToCapped": "mycoll", size: 100*1024*1024});

check if a collection is Capped
db.myCollection.isCapped()

check stats of db
db.stats()

To reclaim deleted space, use either of the following:
--compact, which defragments deleted space. compact requires up to 2 gigabytes of extra disk space to run. Do not use compact if you are critically low on disk space.
--repairDatabase, which rebuilds the database. Both options require additional disk space to run. For details, see Recover MongoDB Data following Unexpected Shutdown.
[Warning]: repairDatabase requires enough free disk space to hold both the old and new database files while the repair is running. Be aware that repairDatabase will block all other operations and may take a long time to complete.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值