1

I have documents like this:

{
   id:1,
  "A": [
    {
      "C": "abc",
      "D": [{X:"test"},{X:"test2"}]
    },
    {
      "C": "fg",
      "D":["X1"]
    }
  ]
}

How to get all id of document whose tag match A-> D -> X has value "test". I can use concatMap() but when I use it I am not able get "id" field and also cannot use it inside map, is there any similar features like $unwind of Mongodb's aggregation framework? Similar to :Querying array of nested objects

[Original Question]

{
id:2,
tags[{a:3,b:4},..]
}
Community
  • 1
  • 1
Prakash Thapa
  • 1,285
  • 14
  • 27

1 Answers1

2

Your originial question had this object:

{ id: 2,
  tags: [ { a: 3, b: 4 }, ... ] }

You can construct a predicate that finds the relevant documents, and pass it to filter.

r.table(...).filter(r.row('tags')('a').contains(3))('id')

In this case, the ('a') part of the query, when applied to an array, returns an array of the a field of each object in that array, if there is one.

Your edited question has a more complicated object, but the principle is the same:

r.table(...).filter(
   r.row('A')('D').concatMap(function(x){return x})('X').contains("test")
)('id')
Etienne Laurin
  • 6,731
  • 2
  • 27
  • 31
  • Thank you for answer, I was expecting something different, so I edit my question. I have to go very deep inside object and array to check whether it exists or not and then finally I have to return first level element. – Prakash Thapa May 14 '14 at 22:15