admin管理员组文章数量:1416314
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?
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?
Share Improve this question edited Sep 22, 2017 at 18:01 CommunityBot 11 silver badge asked Aug 15, 2015 at 11:51 WonkoWonko 1761 silver badge9 bronze badges2 Answers
Reset to default 6You can do an AND in LokiJS, no problem:
var dbRes = recsCol.find({'$and': [{'format':format}, {'cardId':-1}]});
I remend using find for one-off queries. If the query occurs multiple times on resultsets that may change then definitely use a view.
By default, all fields in a query object are treated as an OR. To make it an AND you will need to change your query syntax to the following:
recsCol.find({
$and: [
{'format':format},
{'cardId':-1}
]
});
本文标签: javascriptLokiJS Simple find query returns wrong resultStack Overflow
版权声明:本文标题:javascript - LokiJS: Simple find query returns wrong result - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745246736a2649588.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论