As mlucy said, you can use filter
in conjunction with or
and contains
to get all documents with a specific tag.
If you have an array of tags, you can do the following too:
var tags = ["young", "cricket"];
r.table('posts').filter(function (row) {
return r.expr(tags).contains(function (value) {
return row("tags").contains(value)
});
})
This is more easily extensible than using or
.
Multi Index
You can also create a multi-index for that property. Multi-indexes let you lookup data by any of the values in an array. So, for example:
r.table("posts").indexCreate("tags", {multi: true})
r.table("posts").getAll("young", "cricket", {index: "tags"})
This query would get all the documents with the "young" and "cricket" tag, and it's more performant and cleaner than using the nested contains
.