spiffytech
spiffytech

Reputation: 6592

RethinkDB: Equivalent for "select where field not in (items)"

I have a table that looks like this:

[                                                                                                                                                                                                              
    { "name": "Alpha", "values": {                                                                                                                                                                             
        "someProperty": 1                                                                                                                                                                                      
    }},                                                                                                                                                                                                        
    { "name": "Beta", "values": {                                                                                                                                                                              
        "someProperty": 2                                                                                                                                                                                      
    }},                                                                                                                                                                                                        
    { "name": "Gamma", "values": {                                                                                                                                                                             
        "someProperty": 3                                                                                                                                                                                      
    }}                                                                                                                                                                                                         
]

I want to select all records where someProperty is not in some array of values (e.g., all records where someProperty not in [1, 2]). I want to get back complete records, not just the values of someProperty.

How should I do this with RethinkDB?

Upvotes: 3

Views: 1559

Answers (1)

Joe Doliner
Joe Doliner

Reputation: 2230

In python it would be:

table.filter(lambda doc: r.not(r.expr([1,2]).contains(doc["someProperty"]))

If the array comes from a subquery and you don't want to do it multiple times:

subquery.do(lambda array:
    table.filter(lambda doc: r.not(array.contains(doc["someProperty"]))))

Upvotes: 5

Related Questions