Querying a compound multi-index in RethinkDB -


i trying efficiently retrieve data in following format:

{   "datetime": "1453845345493",   "someids": ["id2000-4", "id1000-34", "id2000-43", "id250-34"] } 

specifically, want "find records have happened since given time, , of those, return have 1 or more of list of ids."

so far followed method shown here creating compound, multi-index using following:

r.db("dbname").table("tablename")   .indexcreate(     "iddatetime",      function(each) {       return each("someids").map(function(id){         return [each("datetime"), id]       })     }     ,{multi: true}) 

this builds index based on values ["1453845345493", "id2000-4"]

but feel i'm in bit deep, , don't know how make query uses index accomplish objective above. how craft query?

i think(i maybe wrong), basically, have 2 types of index lookup:

  • exactly match: get, getall
  • range match: between

so in case, it's cannot use getall because want find records have happened since given time, , of those, return have 1 or more of list of id.

that leave between. let's find way model it.

i suggest change datetime field numeric instead of string. guess storing epoch.

we create index did:

r.table('t11').indexcreate('iddatetime', function(doc) {   return doc('someids').map(function(id){         return [doc("datetime"), id]   }) }, {multi: true}) 

then query similar this:

r.table('t11')  .between([1453845345493, "id1000-34"], [r.maxval, "id1000-34"], {index: 'iddatetime'}) 

to find document since epoch time , contains id1000-34. can find epoch of yesterday using either javascript or rethinkdb datetime function.


update:

while isn't perfect, can simulate either id sth this:

r.expr(["id1000-34", "id1000-4"])   .concatmap(function(needle) {     return r.table('t11')      .between([1453845345499, needle], [r.maxval, needle], {index: 'iddatetime'})   })   .distinct() 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -