mongodb的操作命令

​进入mongodb的bin目录下输入mongo

输入show dbs 查看目前多有的数据库列表

输入 use blog 跳入该blog数据库下

输入 show collections 查看当前数据库的集合

输入db.teacher.find() 查看teacher表中的数据​

    db.users.help()显示所有命令

    db.users.find().help() - show DBCursor help

    db.users.count()

    db.users.copyTo(newColl) - duplicates collection by copying all documents to newColl; no indexes are copied.

    db.users.convertToCapped(maxBytes) - calls {convertToCapped:'users', size:maxBytes}} command

    db.users.createIndex(keypattern[,options])

    db.users.dataSize()

    db.users.distinct( key ) - e.g. db.users.distinct( 'x' )

    db.users.drop() drop the collection

    db.users.dropIndex(index) - e.g. db.users.dropIndex( "indexName" ) or db.users.dropIndex( { "indexKey" : 1 } )

    db.users.dropIndexes()

    db.users.ensureIndex(keypattern[,options]) - DEPRECATED, use createIndex() instead

    db.users.explain().help() - show explain help

    db.users.reIndex()

    db.users.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.

                                                  e.g. db.users.find( {x:77} , {name:1, x:1} )

    db.users.find(...).count()

    db.users.find(...).limit(n)

    db.users.find(...).skip(n)

    db.users.find(...).sort(...)

    db.users.findOne([query])

    db.users.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )

    db.users.getDB() get DB object associated with collection

    db.users.getPlanCache() get query plan cache associated with collection

    db.users.getIndexes()

    db.users.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )



    db.users.insert(obj)

    db.users.mapReduce( mapFunction , reduceFunction , <optional params> )

    db.users.aggregate( [pipeline], <optional params> ) - performs an aggregation on a collection; returns a cursor

    db.users.remove(query)

    db.users.renameCollection( newName , <dropTarget> ) renames the collection.

    db.users.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name

    db.users.save(obj)

    db.users.stats({scale: N, indexDetails: true/false, indexDetailsKey: <index key>, indexDetailsName: <index name>})

    db.users.storageSize() - includes free space allocated to this collection

    db.users.totalIndexSize() - size in bytes of all the indexes

    db.users.totalSize() - storage allocated for all data and indexes

    db.users.update(query, object[, upsert_bool, multi_bool]) - instead of two flags, you can pass an object with fields: upsert, multi

    db.users.validate( <full> ) - SLOW

    db.users.getShardVersion() - only for use with sharding

    db.users.getShardDistribution() - prints statistics about data distribution in the cluster

    db.users.getSplitKeysForChunks( <maxChunkSize> ) - calculates split points over all chunks and returns splitter function

    db.users.getWriteConcern() - returns the write concern used for any operations on this collection, inherited from server/db if set

    db.users.setWriteConcern( <write concern doc> ) - sets the write concern for writes to the collection

    db.users.unsetWriteConcern( <write concern doc> ) - unsets the write concern for writes to the collection
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值