Hi there,
I'm a new user of mongodb and I'm stuck trying to translate in Java a mongoDB query.
Here is the problem. I have a "test" collection such as :
and I would like to query only the second document based on the value of the b field in the embedded documents in the array "a".Code:db.test.find() { "_id" : ObjectId("4e9e9ec65bd7871ef40fc52b"), "a" : [ { "b" : "c" } ] } { "_id" : ObjectId("4e9e9edf5bd7871ef40fc52c"), "a" : [ { "b" : "c" }, { "b" : "d" } ] } { "_id" : ObjectId("4e9e9ee45bd7871ef40fc52d"), "a" : [ { "b" : "d" } ] }
In order to do so, I'm using the "$and" operand (on which I don't have found many information on the web).
I've searched about this query in Java but didn't find out how to use it. I'm using the spring-data-mongodb framework and querying the db through the use of a MongoTemplate object.Code:db.test.find({$and : [{"a.b":"c"},{ "a.b":"d"}]}) { "_id" : ObjectId("4e9e9edf5bd7871ef40fc52c"), "a" : [ { "b" : "c" }, { "b" : "d" } ] }
Thanks for any answer


Reply With Quote
