$and
在集合 foo.bar 插入2条记录:
- > db.foo.bar.insert( { "id": 100, "time": { "$date": "2012-10-01" }, "income": 10000, "expenses": 500 } )
- > db.foo.bar.insert( { "id": 200, "time": { "$date": "2012-10-01" }, "income": 9000, "expenses": 1000 } )
- 查询“time”字段值大于或等于2010年1月1日,并且“income”字段值等于10000的记录
- 查询字段“income”值大于0,并且小于10000的记录:
或者
- > db.foo.bar.find( { "income": { "$gt": 0, "$lt": 10000 } } )
- {
- "_id": {
- "$oid": "5821afcd2b4c38286d000004"
- },
- "time": {
- "$date": "2013-05-01"
- },
- "income": 9000,
- "expenses": 1000
- }