我是新來的MongoDB,我有我的數據庫如下文件:其中對蒙戈陣列條款不起作用
{「_id」:{「$ OID」:「546e916cd38e0b3e0e79592f」},「名「:」hamed「,」entity「:[」1「,」2「]}
現在我想閱讀aal文檔,該實體= [」1「,」2「] 爲此我嘗試了以下代碼:
MongoClient mongoClient = new MongoClient("localhost", 27017);
DB db = mongoClient.getDB("test");
Set<String> colls = db.getCollectionNames();
DBCollection coll = db.getCollection("test");
DBObject oredrFields = new BasicDBObject();
oredrFields.put("entity", ":{ $in: ['1', '2'] } }");
DBCursor cursor = coll.find(oredrFields);
try {
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
} finally {
cursor.close();
}
但它不會返回任何東西......任何人都可以幫助我如何正確地寫我的where子句嗎?