root@dev:~# mongo
MongoDB shell version: ..
connecting to: test
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
rs.help() help on replica set methods
help connect connecting to a db help
help admin administrative help
help misc misc things to know
help mr mapreduce help
show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= ms
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : } ) list objects in foo where a ==
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
db.help()
DB methods:
db.addUser(username, password[, readOnly=false])
db.auth(username, password)
db.cloneDatabase(fromhost)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb, todb, fromhost)
db.createCollection(name, { size : ..., capped : ..., max : ... } )
db.currentOp() displays the current operation in the db
db.dropDatabase()
db.eval(func, args) run code server-side
db.getCollection(cname) same as db['cname'] or db.cname
db.getCollectionNames()
db.getLastError() - just returns the err msg string
db.getLastErrorObj() - return full status object
db.getMongo() get the server connection object
db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair
db.getName()
db.getPrevError()
db.getProfilingLevel() - deprecated
db.getProfilingStatus() - returns if profiling is on and slow threshold
db.getReplicationInfo()
db.getSiblingDB(name) get the db at the same server as this one
db.isMaster() check replica primary status
db.killOp(opid) kills the current operation in the db
db.listCommands() lists all the db commands
db.printCollectionStats()
db.printReplicationInfo()
db.printSlaveReplicationInfo()
db.printShardingStatus()
db.removeUser(username)
db.repairDatabase()
db.resetError()
db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into { cmdObj : }
db.serverStatus()
db.setProfilingLevel(level,<slowms>) =off =slow =all
db.shutdownServer()
db.stats()
db.version() current version of the server
db.getMongo().setSlaveOk() allow queries on a replication slave server
db.mycoll.help()
DBCollection help
db.mycoll.find().help() - show DBCursor help
db.mycoll.count()
db.mycoll.dataSize()
db.mycoll.distinct( key ) - eg. db.mycoll.distinct( 'x' )
db.mycoll.drop() drop the collection
db.mycoll.dropIndex(name)
db.mycoll.dropIndexes()
db.mycoll.ensureIndex(keypattern[,options]) - options is an object with these possible fields: name, unique, dropDups
db.mycoll.reIndex()
db.mycoll.find([query],[fields]) - query is an optional query filter. fields is optional set of fields to return.
e.g. db.mycoll.find( {x:} , {name:, x:} )
db.mycoll.find(...).count()
db.mycoll.find(...).limit(n)
db.mycoll.find(...).skip(n)
db.mycoll.find(...).sort(...)
db.mycoll.findOne([query])
db.mycoll.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
db.mycoll.getDB() get DB object associated with collection
db.mycoll.getIndexes()
db.mycoll.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
db.mycoll.mapReduce( mapFunction , reduceFunction , <optional params> )
db.mycoll.remove(query)
db.mycoll.renameCollection( newName , <dropTarget> ) renames the collection.
db.mycoll.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
db.mycoll.save(obj)
db.mycoll.stats()
db.mycoll.storageSize() - includes free space allocated to this collection
db.mycoll.totalIndexSize() - size in bytes of all the indexes
db.mycoll.totalSize() - storage allocated for all data and indexes
db.mycoll.update(query, object[, upsert_bool, multi_bool])
db.mycoll.validate() - SLOW
db.mycoll.getShardVersion() - only for use with sharding
{
"host" : "dev",
"version" : "..",
"process" : "mongod",
"uptime" : ,
"uptimeEstimate" : ,
"localTime" : ISODate("--T::.Z"),
"globalLock" : {
"totalTime" : ,
"lockTime" : ,
"ratio" : .,
"currentQueue" : {
"total" : ,
"readers" : ,
"writers" :
},
"activeClients" : {
"total" : ,
"readers" : ,
"writers" :
}
},
"mem" : {
"bits" : ,
"resident" : ,
"virtual" : ,
"supported" : true,
"mapped" :
},
"connections" : {
"current" : ,
"available" :
},
"extra_info" : {
"note" : "fields vary by platform",
"heap_usage_bytes" : ,
"page_faults" :
},
"indexCounters" : {
"btree" : {
"accesses" : ,
"hits" : ,
"misses" : ,
"resets" : ,
"missRatio" : .
}
},
"backgroundFlushing" : {
"flushes" : ,
"total_ms" : ,
"average_ms" : .,
"last_ms" : ,
"last_finished" : ISODate("--T::.Z")
},
"cursors" : {
"totalOpen" : ,
"clientCursors_size" : ,
"timedOut" :
},
"network" : {
"bytesIn" : ,
"bytesOut" : ,
"numRequests" :
},
"opcounters" : {
"insert" : ,
"query" : ,
"update" : ,
"delete" : ,
"getmore" : ,
"command" :
},
"asserts" : {
"regular" : ,
"warning" : ,
"msg" : ,
"user" : ,
"rollovers" :
},
"writeBacksQueued" : false,
"ok" :
}
use fragment db.stats()
db.stats()
{
"db" : "fragment",
"collections" : ,
"objects" : ,
"avgObjSize" : .,
"dataSize" : ,
"storageSize" : ,
"numExtents" : ,
"indexes" : ,
"indexSize" : ,
"fileSize" : ,
"ok" :
}
db.getCollectionNames()
db.getCollectionNames()
[
"u",
"baseSe",
"bytravel",
"daodao",
"goeu",
"lotour",
"lvping",
"mafengwo",
"sina",
"sohu",
"system.indexes"
]
show dbs
admin .GB
local (empty)
pagedb .GB
test .GB
use LuceneIndexDB
switched to db LuceneIndexDB
show dbs
admin .GB
local (empty)
pagedb .GB
test .GB
db
LuceneIndexDB
db.storeCollection.save({'version':'.', 'segment':'eol'})
show dbs
LuceneIndexDB .GB
admin .GB
local (empty)
pagedb .GB
test .GB
<em>db.storeCollection.save({'version':'3.5', 'segment':'e3ol6'})</em>
db.storeCollection.remove({'version':'.'})
db.storeCollection.findOne()
null
use pagedb
switched to db pagedb
db.page.ensureIndex({'title':, 'url':-})
db.system.indexes.find()
{ "name" : "_id_", "ns" : "pagedb.page", "key" : { "_id" : }, "v" : }
{ "name" : "_id_", "ns" : "pagedb.system.users", "key" : { "_id" : }, "v" : }
{ "_id" : ObjectId("efcfcaccd"), "ns" : "pagedb.page", "key" : {"title" : , "url" : - }, "name" : "title__url_-", "v" : }
db.page.getIndexes()
[
{
"name" : "_id_",
"ns" : "pagedb.page",
"key" : {
"_id" :
},
"v" :
},
{
"_id" : ObjectId("efcfcaccd"),
"ns" : "pagedb.page",
"key" : {
"title" : ,
"url" : -
},
"name" : "title__url_-",
"v" :
}
]
db.mycoll.dropIndex(name) db.mycoll.dropIndexes()
use fragment db.baseSe.count()
use fragment switched to db fragment db.baseSe.count()
use fragment db.baseSe.find().count()
use fragment db.baseSe.storageSize() 142564096
db.baseSe.totalSize() 144096000
mongod --dbpath /usr/mongo/data --logfile /var/mongo.log
mongod --auth --dbpath /usr/mongo/data --logfile /var/mongo.log
mongod --repair
mongod -f /etc/mongodb.conf --repair
db.shutdownServer()
mongod --auth --dbpath /usr/mongo/data --logfile /var/mongo.log
db.addUser("admin", ",%F23_kj~00Opoo0+\/")
db.auth("admin", ",%F23_kj~00Opoo0+\/")
{
"user" : "admin",
"readOnly" : false,
"pwd" : "debfcbabbecd"
}
db.runCommand({fsync:1,lock:1})
db.currentOp()
use admin db.$cmd.sys.unlock.findOne()
db.currentOp()
mkdir testbak cd testbak mongodump
mongodump -d pagedb
mongodump -d pagedb -c page
cd testbak mongorestore --drop
cd testbak mongorestore -d pagedb --drop
cd testbak mongorestore -d pagedb -c page --drop
mongoimport -d pagedb -c page --type csv --headerline --drop < csvORtsvFile.csv
mongoexport -d pagedb -c page -q {} -f _id,title,url,spiderName,pubDate --csv > pages.csv
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有