mongodb一些常用query命令

mongoDB的备份

./mongodump -h 127.0.0.1  -d dbname -c collectionName -o bakDir



mongoDB的query语句:

 

select:

 

      db.users.find({})
 
      db.users.find({'last_name': 'Smith'})
 
 field selection:
 
    //只取ssn  相当于 select ssn from db where last_name == 'Smith'
    // retrieve ssn field for documents where last_name == 'Smith':
    db.users.find({last_name: 'Smith'}, {'ssn': 1});

    //除了域 thumbnail ,其他的域都取
    // retrieve all fields *except* the thumbnail field, for all documents:
    db.users.find({}, {thumbnail:0});

 

 

Sorting

MongoDB queries can return sorted results. To return all documents and sort by last name in ascending order, we'd query like so:

  db.users.find({}).sort({last_name: 1});
{last_name: 1} 升序    
{last_name: 0} 降序
Skip and Limit

MongoDB also supports skip and limit for easy paging. Here we skip the first 20 last names, and limit our result set to 10:

db.users.find().skip(20).limit(10);
db.users.find({}, {}, 10, 20); // same as above, but less clear


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值