Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LokiJS: Simple find query returns wrong result

In LokiJS I try a very simple query (which I assume is AND):

var dbRes = recsCol.find({'format':format, 'cardId':-1});

after inserting some data with

recsCol.insert({format:format, cardId:id, recCardId:key, amount:item[key]});

that doesn't contain a cardId of -1.

The query still yields results. Is this expected behaviour? If so, how can I make the fields match exactly so that I won't get a result in this case?

like image 793
Wonko Avatar asked Dec 25 '22 15:12

Wonko


1 Answers

You can do an AND in LokiJS, no problem:

var dbRes = recsCol.find({'$and': [{'format':format}, {'cardId':-1}]});

I recommend using find for one-off queries. If the query occurs multiple times on resultsets that may change then definitely use a view.

like image 112
Joe Minichino Avatar answered Dec 27 '22 04:12

Joe Minichino