匹配 RethinkDB 中给定数据数组的至少一个元素
match atleast one element of given array of data in RethinkDB
我有如下数据集-
[{
"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)
})
我有如下数据集-
[{
"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)
})