mongodb doc学习

1.开启/关闭服务

  • sudo service mongodb start
  • sudo service mongodb stop
  • sudo service mongodb restart
  • mongod --config /etc/mongodb.conf #通过配置文件启动
fork = true
bind_ip = 127.0.0.1,10.8.0.10,192.168.4.24
port = 27017
quiet = true
dbpath = /srv/mongodb
logpath = /var/log/mongodb/mongod.log
logappend = true
journal = true
nounixsocket = true
auth = true
replSet = set0
keyFile = /srv/mongodb/keyfile
configsvr = true
pidfilepath = /srv/mongodb/db0.pid
slowms = 50
profile = 3
verbose = true
diaglog = 3
objcheck = true
cpu = true


2.shell中连接mongod

mongo --port --host 


3.查看命令

show dbs

show collections


4.查询

db.collection.findOne()#返回一个

db.collection.find() #全部查询,返回cursor

db.collection.find({条件1:value,条件2:value,。。。})#条件查询

db.collection.find().limit(X)#限制查询,返回X个数据


你可能感兴趣的:(mongo)