Question

I need help in ydn db. My issue is as follows: How can I fetch records by 2 conditions? In sql it would be:

"SELECT * FROM store WHERE name='Test' AND cool=1;"

Currently my attempt looks like this:

var keyRange = ydn.db.KeyRange.bound(['Test', true]);

var db = DB.getDatabase();

database
.get('personStore', 'name, cool', keyRange)
.done(function(records) {
    console.log(records);
});

Thanks in advance :-)

Était-ce utile?

La solution

As discussed in this page, you can use compound index (as you did) or key joining. If you index ['name', 'cool'], you should be able to query by ydn.db.KeyRange.only(['Test', 1]). Note that boolean is not a valid key. Even if cool is boolean value, you have to index as integer value. But my suggestion is index only name and, just query name and filter out cool value on the result set.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top