MongoDB命令备忘
来源:互联网 发布:拉乌网络 编辑:程序博客网 时间:2024/05/17 00:53
E:\>cd mongodb
E:\mongodb>bin\mongod --help
Allowed options:
General options:
-h [ --help ] show this usage information
--version show version information
-f [ --config ] arg configuration file specifying additional options
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
--quiet quieter output
--port arg specify port number - 27017 by default
--bind_ip arg comma separated list of ip addresses to listen on
- all local ips by default
--maxConns arg max number of simultaneous connections - 20000 by
default
--logpath arg log file to send write to instead of stdout - has
to be a file, not directory
--logappend append to logpath instead of over-writing
--pidfilepath arg full path to pidfile (if not set, no pidfile is
created)
--keyFile arg private key for cluster authentication
--setParameter arg Set a configurable parameter
--auth run with security
--cpu periodically show cpu and iowait utilization
--dbpath arg directory for datafiles - defaults to \data\db\
--diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads
--directoryperdb each database will be stored in a separate
directory
--ipv6 enable IPv6 support (disabled by default)
--journal enable journaling
--journalCommitInterval arg how often to group/batch commit (ms)
--journalOptions arg journal diagnostic options
--jsonp allow JSONP access via http (has security
implications)
--noauth run without security
--nohttpinterface disable http interface
--nojournal disable journaling (journaling is on by default
for 64 bit)
--noprealloc disable data file preallocation - will often hurt
performance
--noscripting disable scripting engine
--notablescan do not allow table scans
--nssize arg (=16) .ns file size (in MB) for new databases
--profile arg 0=off 1=slow, 2=all
--quota limits each database to a certain number of files
(8 default)
--quotaFiles arg number of files allowed per db, requires --quota
--repair run repair on all dbs
--repairpath arg root directory for repair files - defaults to
dbpath
--rest turn on simple rest api
--slowms arg (=100) value of slow for profile and console log
--smallfiles use a smaller default file size
--syncdelay arg (=60) seconds between disk syncs (0=never, but not
recommended)
--sysinfo print some diagnostic system information
--upgrade upgrade db if needed
Windows Service Control Manager options:
--install install Windows service
--remove remove Windows service
--reinstall reinstall Windows service (equivalent to --remove
followed by --install)
--serviceName arg Windows service name
--serviceDisplayName arg Windows service display name
--serviceDescription arg Windows service description
--serviceUser arg account for service execution
--servicePassword arg password used to authenticate serviceUser
Replication options:
--oplogSize arg size to use (in MB) for replication op log. default is
5% of disk space (i.e. large is good)
Master/slave options (old; use replica sets instead):
--master master mode
--slave slave mode
--source arg when slave: specify master as <server:port>
--only arg when slave: specify a single database to replicate
--slavedelay arg specify delay (in seconds) to be used when applying
master ops to slave
--autoresync automatically resync if slave data is stale
Replica set options:
--replSet arg arg is <setname>[/<optionalseedhostlist>]
--replIndexPrefetch arg specify index prefetching behavior (if secondary)
[none|_id_only|all]
Sharding options:
--configsvr declare this is a config db of a cluster; default port
27019; default dir /data/configdb
--shardsvr declare this is a shard db of a cluster; default port
27018
E:\mongodb>start .\bin\mongod -port 10000 -dbpath data\db -logpath data\log\mdb.log
E:\mongodb>bin\mongo --help
MongoDB shell version: 2.4.8
usage: bin\mongo [options] [db address] [file names (ending in .js)]
db address can be:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
options:
--shell run the shell after executing files
--nodb don't connect to mongod on startup - no
'db address' arg expected
--norc will not run the ".mongorc.js" file on
start up
--quiet be less chatty
--port arg port to connect to
--host arg server to connect to
--eval arg evaluate javascript
-u [ --username ] arg username for authentication
-p [ --password ] arg password for authentication
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR)
authentication mechanism
-h [ --help ] show this usage information
--version show version information
--verbose increase verbosity
--ipv6 enable IPv6 support (disabled by
default)
file names: a list of files to run. files have to end in .js and will exit after
unless --shell is specified
E:\mongodb>bin\mongo -port 10000
MongoDB shell version: 2.4.8
connecting to: 127.0.0.1:10000/test
Server has startup warnings:
Sun Nov 24 11:24:51.515 [initandlisten]
Sun Nov 24 11:24:51.515 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary
.
Sun Nov 24 11:24:51.515 [initandlisten] ** 32 bit builds are limited to le
ss than 2GB of data (or less with --journal).
Sun Nov 24 11:24:51.515 [initandlisten] ** Note that journaling defaults t
o off for 32 bit and is currently off.
Sun Nov 24 11:24:51.515 [initandlisten] ** See http://dochub.mongodb.org/c
ore/32bit
Sun Nov 24 11:24:51.515 [initandlisten]
Sun Nov 24 11:24:51.515 [initandlisten] ** NOTE: your operating system version d
oes not support the method that MongoDB
Sun Nov 24 11:24:51.515 [initandlisten] ** uses to detect impending page f
aults.
Sun Nov 24 11:24:51.515 [initandlisten] ** This may result in slower perfo
rmance for certain use cases
Sun Nov 24 11:24:51.515 [initandlisten]
> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce
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 wit
h time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memor
y, 'global' is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to f
urther iterate
DBQuery.shellBatchSize = x set default number of items to display on s
hell
exit quit the mongo shell
> show dbs;
local 0.03125GB
> use mydb;
switched to db mydb
> show dbs;
local 0.03125GB
> db.myc.save({a:10});
> db.myc.find();
{ "_id" : ObjectId("529172a4eac97f31b4051e3b"), "a" : 10 }
> show collections;
myc
system.indexes
> show dbs;
local 0.03125GB
mydb 0.0625GB
> db.dropDatabase();
{ "dropped" : "mydb", "ok" : 1 }
> show dbs;
local 0.03125GB
> exit;
E:\mongodb>exit
==================================================
**************
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
E:\mongodb>bin\mongod --repair --dbpath data\db
其他命令可以参考:
http://blog.csdn.net/wangpeng047/article/details/7705588
下载:
http://www.mongodb.org/downloads
https://github.com/mongodb/mongo-java-driver/downloads