查询嵌套对象数组 [英] Querying array of nested objects
本文介绍了查询嵌套对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个 JSON(示例 - 可以在 apple itunes RSS feed) 存储在名为test"的 RethinkDB 表中:
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..."
}
}
]
}
}
我将如何在 JavaScript 中编写 ReQL 查询,以获取包含 title 的所有条目 (entry
) 的summary字符串xyz"?我希望查询结果返回一组匹配的 entry 对象,而不是一组匹配的 feed.
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.
推荐答案
如果我正确理解你想要做什么,这个查询应该就是你要找的:
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")
})
这篇关于查询嵌套对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文