Re: [mongodb-user] How to query inner document in mongodb using mongodb-java-driver

18 views
Skip to first unread message

Jorge Puente Sarrín

unread,
Nov 16, 2012, 11:07:23 AM11/16/12
to mongod...@googlegroups.com
Hi,

You can do it so:

Mongo con = new Mongo();
DBCollection col = db.getCollection("collection");
BasicDBObject query = new BasicDBObject("people.address.state", "CA");
DBCursor cursor = col.find(query)
;

http://www.mongodb.org/display/DOCS/Java+Tutorial




2012/11/15 liumingyuan <lzc...@gmail.com>

I am new to MongoDB. And now i got a puzzle: say i've got a query workable in mongo console


{
    "people":{
                "name":"arthur",
                "tele": "001-837475"
                "address":{
                             "country":"us",
                             "state" : "CA",
                             "city" : "LA"
                          }
             }
}

I've got pretty many record like this. & I want to query for all people who come from CA. The query below works well in mongo shell


 db.test.find("people.address.state":"CA")

But I must do the query in Java. Perhaps using DBObject or BasicDBObject,

PS: I don't want to use other opensource packages. just the mongodb-java-driver would be delightful.

Thanks.

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb



--
Jorge Puente Sarrín.
Reply all
Reply to author
Forward
0 new messages