亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

query - mongodb如何只根據(jù)內(nèi)嵌文檔里的鍵值對來檢索出整個document
PHPz
PHPz 2017-04-21 11:16:21
0
1
789
{
    "_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的鏈接, 也沒有人回答.那個回答也不管用.

謝謝了.!

PHPz
PHPz

學(xué)習(xí)是最好的投資!

reply all(1)
阿神
    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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template