gpt4 book ai didi

node.js - 匹配 RethinkDB 中给定数据数组的至少一个元素

转载 作者:太空宇宙 更新时间:2023-11-04 00:12:25 25 4
gpt4 key购买 nike

我有一个如下的数据集-

[{
"name": "new name",
"tags":[{
"addedBy": "userABCe3" ,
"addedDTS": Tue Jan 23 2018 13:02:37 GMT+00:00 ,
"tagId": "08d679c8-31b6-48d3-b8f3-3ab89f7bb821"
},{
"addedBy": "userABCe3" ,
"addedDTS": Tue Jan 23 2018 13:02:37 GMT+00:00 ,
"tagId": "08d679c8-31b6-48d3-b8f3-3ab89f7bb823"
}]
},
{
"name": "data 1",
"tags":[{
"addedBy": "userABCe3" ,
"addedDTS": Tue Jan 23 2018 13:02:37 GMT+00:00 ,
"tagId": "08d679c8-31b6-48d3-b8f3-3ab89f7bb823"
},{
"addedBy": "userABCe3" ,
"addedDTS": Tue Jan 23 2018 13:02:37 GMT+00:00 ,
"tagId": "08d679c8-31b6-48d3-b8f3-3ab89f7bb824"
}]
}]

我需要查询给定 tagIds 数组中至少有一个匹配的数据

[ "08d679c8-31b6-48d3-b8f3-3ab89f7bb824", "08d679c8-31b6-48d3-b8f3-3ab89f7bb822"]

预期结果如下:

[{
"name": "data 1",
"tags":[{
"addedBy": "userABCe3" ,
"addedDTS": Tue Jan 23 2018 13:02:37 GMT+00:00 ,
"tagId": "08d679c8-31b6-48d3-b8f3-3ab89f7bb823"
},{
"addedBy": "userABCe3" ,
"addedDTS": Tue Jan 23 2018 13:02:37 GMT+00:00 ,
"tagId": "08d679c8-31b6-48d3-b8f3-3ab89f7bb824"
}]
}]

提前致谢

最佳答案

这个查询对我有用

r.db('dbName').table("tableName").filter(function(doc){
var tags = doc('tags')('tagId');
var tagIds = ['08d679c8-31b6-48d3-b8f3-3ab89f7bb881','08d679c8-31b6-48d3-b8f3-3ab89f7bb823' ];
var query = tagIds.map(function(tagId){
return tags.contains(tagId)
});
return r.expr(query).contains(true)
})

关于node.js - 匹配 RethinkDB 中给定数据数组的至少一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48866554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com