如何编写和或在mongoDb中的相同查询? 说如果我想在mongoDb中写下面的查询,我该怎么做。如何在mongoDb中编写和/或在同一个查询中?
select * from emp where (empid > 200 and dept_id=5) or dept_id <=4;
如果集合包含下面列约对比查询operters here
emp_id,emp_name,dept_id,sal
如何编写和或在mongoDb中的相同查询? 说如果我想在mongoDb中写下面的查询,我该怎么做。如何在mongoDb中编写和/或在同一个查询中?
select * from emp where (empid > 200 and dept_id=5) or dept_id <=4;
如果集合包含下面列约对比查询operters here
emp_id,emp_name,dept_id,sal
试试这个:
db.coll.find({
$or: [
{
$and: [
{
emp_id: { $gt: 200 },
},
{
dept_id: 5
}
]
},
{
dept_id: { $lte: 4 }
}
]
})
或更容易(在这种情况下):
db.coll.find({
$or: [
{
emp_id: { $gt: 200 },
dept_id: 5
}
{
dept_id: { $lte: 4 }
}
]
})
我就** **强烈建议你花一些时间,通过这个页面去:http://docs.mongodb.org/manual/reference/sql-comparison/ –