{ "_id": { "$oid": "50a5e1cd703d7e9c65326bf9"
}, "name":"arthur", "tele": "001-837475"
"address":{ "country":"us", "state" : "CA", "city" : "LA"
}
}
}我的mongodb中存了很多这样的数据.我有这样的检索需求.查找所有来自加州的人.在shell里是这样query: db.test.find({"address.state":"CA"})并且能够返回正确的结果.
1 回答
侃侃尔雅
TA贡献1801条经验 获得超15个赞
Mongo db = new Mongo("localhost", 27017); DBCollection coll = db.getCollection("collectionname"); DBObject query = new BasicDBObject("address.state","CA"); DBCursor cursor = coll.find(query); while(cursor.hasNext()){ System.out.println(cursor.next()); } cursor.close()
- 1 回答
- 0 关注
- 148 浏览
添加回答
举报
0/150
提交
取消