MongoDB笔记3-shell collection对象

本文档详细介绍了MongoDB shell中collection对象的各种方法,包括find、count、drop、distinct、ensureIndex等,涵盖了数据查询、索引管理、集合操作等方面,帮助开发者更好地理解和操作MongoDB数据库。
摘要由CSDN通过智能技术生成
#mongoDB shell 中collection对象的方法
手册: 传送门
版本:3.0.2

#method list:
>db.getCollection("coll").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  ,然后
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值