{ "_id": { "$oid": "50a5e1cd703d7e9c65326bf9" }, "name":"arthur", "tele": "001-837475" "address":{ "country":"us", "state" : "CA", "city" : "LA" } } }
我的mongodb中存了很多這樣的數(shù)據(jù).我有這樣的檢索需求.查找所有來自加州的人.
在shell里是這樣query:
db.test.find({"address.state":"CA"})
并且能夠返回正確的結(jié)果.
我想用mongodb-java-builder來檢索數(shù)據(jù)庫.如何書寫代碼呢?
這個問題已經(jīng)困擾了我好久了.
這是我的問題的stackoverflow的鏈接, 也沒有人回答.那個回答也不管用.
謝謝了.!
學(xué)習(xí)是最好的投資!
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()
I didn’t read the document carefully. I made such a mistake. I shouldn’t, reflect on it here.