arrays - OR query in rethink -


is possible or search on values of array in rethink.

eg: have table called "post" field "tags" array. want or search on values of tags.

post1 { tags : ["young","agreesive"] }  post2 { tags : ["cricket","india"] } 

give me posts contains tags "young" or "cricket" should return both posts.

as mlucy said, can use filter in conjunction or , contains documents specific tag.

if have array of tags, can 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 more extensible using or.

multi index

you can create multi-index property. multi-indexes let lookup data of values in array. so, example:

r.table("posts").indexcreate("tags", {multi: true}) r.table("posts").getall("young", "cricket", {index: "tags"}) 

this query documents "young" , "cricket" tag, , it's more performant , cleaner using nested contains.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -