#mongoDB shell 中collection对象的方法
db.coll.count()
db.coll.copyTo(newColl)
db.coll.dataSize()
db.coll.distinct( key ) - e.g. db.coll.distinct( 'x' )
db.coll.drop()
db.coll.dropIndex(index) - e.g. db.coll.dropIndex( "indexName" ) or db.coll.dropIndex( { "indexK
ey" : 1 } )
db.coll.dropIndexes()
手册:
传送门
版本:3.0.2
#method list:
>db.getCollection("coll").help()
DBCollection help #db.coll是数据库下一个名为coll的collection
db.coll.find().help() - show DBCursor help
DBCollection help #db.coll是数据库下一个名为coll的collection
db.coll.find().help() - show DBCursor help
#显示DBCursor的帮助信息(方法列表)
db.coll.count()
#返回此collection下document的个数
db.coll.copyTo(newColl)
#将当前collection拷贝一份到当前数据库下的名为newColl的collection,但是建立的索引不会拷贝
db.coll.convertToCapped(maxBytes)
#调用 {convertToCapped:'coll', size:maxBytes}}命令,把当前collection转成capped collection,并将其maxSize更新为maxBytes
#如果maxBytes不是4096的倍数,那么将采用进一法convertToCapped(4097)等价于convertToCapped(4096*2) --关于这个手册没写,是规律(什么鬼=_=#)
#capped collection:固定大小的collection,当插入的document超过设定的大小时,会自动覆盖最早插入的document
#(once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.)
#maxBytes是指定的大小,单位应该是byte吧,
看手册collStats.size
db.coll.dataSize()
#返回当前collection的大小,(随数据插入而变大)
db.coll.distinct( key ) - e.g. db.coll.distinct( 'x' )
#遍历当前collection下的所有document的名为key的field的值,然后返回一个这些值的数组(去重)
db.coll.drop()
#删除当前collection
db.coll.dropIndex(index) - e.g. db.coll.dropIndex( "indexName" ) or db.coll.dropIndex( { "indexK
ey" : 1 } )
#删除根据索引名字删除索引
db.coll.dropIndexes()
#删除所有索引
db.coll.ensureIndex(keypattern[,options])
#从版本3.0开始,
Deprecated ,然后