【发布时间】:2013-02-22 02:29:04
【问题描述】:
我对 mongo 有点陌生。我想在一个字段上查询多个值。 在 SQL 中,我想要这样的东西:
select * from table where field in ("foo","bar")
假设我在 mongodb 中有以下文档
{
"_id":"foo"
}
{
"_id":"bar"
}
我只是想模仿这个查询:
db.coll.find( { _id: { $in: [ "foo", "bar" ] } } );
我想检索 _id 为“foo”或“bar”的所有文档。 我想使用 java 驱动程序来做到这一点。
我尝试了类似的东西
BasicDBObject query = new DBObject()
query.append("_id","foo");
query.append("_id","bar");
collection.find(query);
但这似乎只返回“bar”文档。
请帮忙
【问题讨论】:
标签: mongodb mongodb-java