启用,重启,停止命令
service mongod start
service mongod stop
service mongod restart
service mongod stop
service mongod restart
登录数据库
mongo -u <user> -p <pass> --host <host> --port 28015
help信息
HELP
db.foo.help() help on collection methods
db.foo.find() list objects in collection foo
db.foo.save({a: 1}) save a document to collection foo
db.foo.update({a: 1}, {a: 2}) update document where a == 1
db.foo.find({a: 1}) list objects in foo where a == 1
it use to further iterate over a cursor
db.foo.find() list objects in collection foo
db.foo.save({a: 1}) save a document to collection foo
db.foo.update({a: 1}, {a: 2}) update document where a == 1
db.foo.find({a: 1}) list objects in foo where a == 1
it use to further iterate over a cursor
往scores表中插入数据,字段:name:'Jim,scores:[75,99,87.2]
db.scores.save({name: 'Jim', scores: [75, 99, 87.2]});
查看数据:
[
{ "name" : "Jim", "scores" : [ 75, 99, 87.2 ], "_id" : { "$oid" : "5185f297cc93742c16064df1" } }
]
]
基本查询语句 查找所有 where a == 2:
db.scores.find({a: 2});
查找所有 where a > 15?
db.scores.find({a: {'$gt': 15}});
其他表达式:
$lt - 小于
$lte - 小于等于
$gte - 大于等于
如:db.scores.find({a: {'$gte': 2, '$lte': 4}});
$ne - 不等于
$in - 在范围内
如:db.scores.find({a: {'$in': [2, 3, 4]}});
$nin - 不在范围内
$lte - 小于等于
$gte - 大于等于
如:db.scores.find({a: {'$gte': 2, '$lte': 4}});
$ne - 不等于
$in - 在范围内
如:db.scores.find({a: {'$in': [2, 3, 4]}});
$nin - 不在范围内