8

Say I have this JSON (sample - a real-life example can be found at apple itunes rss feed) stored in a RethinkDB table called 'test':

{
    "feed": {
        "entry": [
            {
                "title": {
                    "label": "Some super duper app"
                },
                "summary": {
                    "label": "Bla bla bla..."
                }
            },
            {
                "title": {
                    "label": "Another awsome app"
                },
                "summary": {
                    "label": "Lorem ipsum blabla..."
                }
            }
        ]
    }
}

How would I write a ReQL query in JavaScript in order to fetch the summary of all entries (entry) which have title containing the string "xyz"? I expect the query result to return an array of matching entry objects, not an array of matching feed.

1 Answer 1

11

If I properly understood what you want to do, this query should be what you are looking for:

r.table("feeds").concatMap(function(doc) {
    return doc("feed")("entry")
}).filter(function(entry) {
    return entry("title")("label").match("xyz")
})
Sign up to request clarification or add additional context in comments.

4 Comments

@neumino, if there was "id" at the top level like: {id:1, feed: ....} How to get this id after matching this text? for example: get all the ids of docs whose feed->entry->title->label match "xyz"? is there anyway to do that?
You can chain with ("id") or map(function(doc) { return doc("id") })
@neumino could you elaborate a bit on that? where in the chain should I apply that map call? I've tried replicating it on a similar case but the stream resulting after concatMap...filter won't have the top level property (id in the example)
@neumino I found this gist of yours stackoverflow.com/questions/21976586/… that solves my issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.