Querying array of nested objects

南楼画角 提交于 2019-12-22 04:17:22

问题


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:


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")
})


来源:https://stackoverflow.com/questions/21976586/querying-array-of-nested-objects

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!