The Rethinkdb predicate function contains "for several values ​​that do not work

I have a data scheme that looks like this:

{
  "datetime": "1453845345493",
  "someIds": ["id2000-4", "id1000-34"]
}

If the array someIdscan contain many different values.

Filtering based on a single identifier using the following query works without problems and returns approximately 400 results. (I also plan to implement the correct indexes, but at the moment I'm testing a simpler case.)

r.db("dbName").table("tableName")
  .filter(r.row("datetime").gt(1453845340493))
  .filter(function(someVal){
    return someVal("someIds").contains("id2000-4");
  })
  .count()

But trying to follow the last example in the documentation “contains” , where it is recommended to use the predicate function to simulate the output of 'or' nothing, when it should return a superset above:

r.db("dbName").table("tableName")
  .filter(r.row("datetime").gt(1453845340493))
  .filter(function(someVal){
    return r.expr(["id2000-4", "id1000-77"]).contains(someVal("someIds"));
  })
  .count()

, , . RethinkDB v2.2.3-1, . ?

+4
1

r.expr(ARRAY).contains(SINGLE_VAL), r.expr(ARRAY).contains(OTHER_ARRAY). , someIds - , https://www.rethinkdb.com/api/javascript/set_intersection/. ( - .filter(function(someVal) { return r.expr(ARRAY).setIntersection(someVal('someIds')).count().ne(0); }).)

contains, :

.filter(function(someVal) {
  return someVal('someIds').contains(function(someId) {
    return r.expr(ARRAY).contains(someId);
  });
})
+4

Source: https://habr.com/ru/post/1626108/


All Articles