query - mongodb如何只根据内嵌文档里的键值对来检索出整个document
PHPz
PHPz 2017-04-21 11:16:21
0
1
607
{ "_id": { "$oid": "50a5e1cd703d7e9c65326bf9" }, "name":"arthur", "tele": "001-837475" "address":{ "country":"us", "state" : "CA", "city" : "LA" } } }

我的mongodb中存了很多这样的数据.我有这样的检索需求.查找所有来自加州的人.
在shell里是这样query:

db.test.find({"address.state":"CA"})

并且能够返回正确的结果.

我想用mongodb-java-builder来检索数据库.如何书写代码呢?
这个问题已经困扰了我好久了.

这是我的问题的stackoverflow的链接, 也没有人回答.那个回答也不管用.

谢谢了.!

PHPz
PHPz

学习是最好的投资!

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
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!