Jazzy
Jazzy

Reputation: 6149

Using Riak.js / Riak, how do I do an "AND" select?

I am trying to determine the existence of an object to decide whether to create a new object with a new key or to update an existing object. The goal here is to match on two Secondary Indexes.

db.query(bucket, {end: null, definition_id: id}, function(err, data) {
    if (err) {
        res.send(err);
    } else {
        if (data.length === 0) {
            // write new obj
        } else {
            // add to current obj
        }
    }
});

If there is an easy way to do this with the HTTP API I would be game for that, too, just can't seem to find it in the docs.

Thanks.

Upvotes: 0

Views: 78

Answers (1)

Joe
Joe

Reputation: 28356

Riak's secondary indexing doesn't support querying 2 indexes simultaneously, you would need to query each index separately and then intersect the result sets.

However, if you need to routinely query the same pair of indexes, you can create a composite index in addition to the others. So if you are indexing, end and definition_id, also create a end-def index whose values are the end and definition_id concatenated with a separator.

Upvotes: 3

Related Questions