Announcement Announcement Module
Collapse
No announcement yet.
And query document based on the same field in an array of json in java Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • And query document based on the same field in an array of json in java

    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 :
    Code:
    db.test.find()
    { "_id" : ObjectId("4e9e9ec65bd7871ef40fc52b"), "a" : [ { "b" : "c" } ] }
    { "_id" : ObjectId("4e9e9edf5bd7871ef40fc52c"), "a" : [ { "b" : "c" }, { "b" : "d" } ] }
    { "_id" : ObjectId("4e9e9ee45bd7871ef40fc52d"), "a" : [ { "b" : "d" } ] }
    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".

    In order to do so, I'm using the "$and" operand (on which I don't have found many information on the web).
    Code:
     db.test.find({$and : [{"a.b":"c"},{ "a.b":"d"}]})
    { "_id" : ObjectId("4e9e9edf5bd7871ef40fc52c"), "a" : [ { "b" : "c" }, { "b" : "d" } ] }
    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.

    Thanks for any answer

  • #2
    We are still working on the $and support for the Query/Criteria classes. We added an and() method to the Query recently but we are also considering re-working the $and/$or support to be easier to use.

    See these issues for progress:
    https://jira.springsource.org/browse/DATADOC-283
    https://jira.springsource.org/browse/DATADOC-300

    Comment


    • #3
      Ok. Thanks for this answer.

      This example is what I need.

      I've seen here that the RC1 release is due to monday so I'll wait until there.

      Comment


      • #4
        We've changed the release plans now and there will be an M5 release early next week to be followed by and RC1 release in a few weeks. The new $or/$nor/$and support for the Criteria class will be in M5.

        Comment

        Working...
        X