0.启动
./mongod --fork -f ../conf/config
/opt/soft/mongodb/bin/mongod --config /opt/soft/mongodb/config/mongo.config
config内容如下:
dbpath=/data/mongodb/data
bind_ip=127.0.0.1
port=27017
logpath=/data/mongodb/logs/mongo.log
logappend=true
fork=true
1.条件操作符
$gt : >
$lt : <
$gte: >=
$lte: <=
$ne : !=、<>
$in : in
$nin: not in
$all: all
$not: 反匹配(1.3.3及以上版本)
2.查询 name <> "bruce" and age >= 18 的数据
db.users.find({name: {$ne: "bruce"}, age: {$gte: 18}});
3.查询 creation_date > '2010-01-01' and creation_date <= '2010-12-31' 的数据
db.users.find({creation_date:{$gt:new Date(2010,0,1), $lte:new Date(2010,11,31)});
4.查询 age in (20,22,24,26) 的数据
db.users.find({age: {$in: [20,22,24,26]}});
5.查询 age取模10等于0 的数据
db.users.find('this.age % 10 == 0');
或者
db.users.find({age : {$mod : [10, 0]}});
6.匹配所有
db.users.find({favorite_number : {$all : [6, 8]}});
可以查询出{name: 'David', age: 26, favorite_number: [ 6, 8, 9 ] }
可以不查询出{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }
7.查询不匹配name=B*带头的记录
db.users.find({name: {$not: /^B.*/}});
查询 age取模10不等于0 的数据
db.users.find({age : {$not: {$mod : [10, 0]}}});
8.建索引
function () {
db.collectionName.ensureIndex({"filedName": 1})
}
9.连接:
./mongo -host {ip} -port {port}
10.状态:
./mongostat -host {ip} -port {port}
./mongod --fork -f ../conf/config
/opt/soft/mongodb/bin/mongod --config /opt/soft/mongodb/config/mongo.config
config内容如下:
dbpath=/data/mongodb/data
bind_ip=127.0.0.1
port=27017
logpath=/data/mongodb/logs/mongo.log
logappend=true
fork=true
1.条件操作符
$gt : >
$lt : <
$gte: >=
$lte: <=
$ne : !=、<>
$in : in
$nin: not in
$all: all
$not: 反匹配(1.3.3及以上版本)
2.查询 name <> "bruce" and age >= 18 的数据
db.users.find({name: {$ne: "bruce"}, age: {$gte: 18}});
3.查询 creation_date > '2010-01-01' and creation_date <= '2010-12-31' 的数据
db.users.find({creation_date:{$gt:new Date(2010,0,1), $lte:new Date(2010,11,31)});
4.查询 age in (20,22,24,26) 的数据
db.users.find({age: {$in: [20,22,24,26]}});
5.查询 age取模10等于0 的数据
db.users.find('this.age % 10 == 0');
或者
db.users.find({age : {$mod : [10, 0]}});
6.匹配所有
db.users.find({favorite_number : {$all : [6, 8]}});
可以查询出{name: 'David', age: 26, favorite_number: [ 6, 8, 9 ] }
可以不查询出{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }
7.查询不匹配name=B*带头的记录
db.users.find({name: {$not: /^B.*/}});
查询 age取模10不等于0 的数据
db.users.find({age : {$not: {$mod : [10, 0]}}});
8.建索引
function () {
db.collectionName.ensureIndex({"filedName": 1})
}
9.连接:
./mongo -host {ip} -port {port}
10.状态:
./mongostat -host {ip} -port {port}