对LokiJs集合的芒果查询会更改集合的大小

时间:2018-10-15 14:45:34

标签: node.js lokijs

我将LokiJs用作应用程序的内存缓存,该应用程序将数据存储在CouchDB中,并允许通过NodeJS服务器进行检索。根据{{​​3}},我的查询结果分配给一个结果集对象:

let result = combinedCache.find({'left.errorCode': errorCode});

combinedCache集合是另外两个集合的.eqJoin的结果:

    var cache = new loki('loki.db');

    errorCodeCache = cache.addCollection('errorCodes');
    messageCache = cache.addCollection('messages');
    errorCodeCache.insert(docs.errorCodes);
    messageCache.insert(docs.messages);
    combinedCache = errorCodeCache.eqJoin(
        messageCache,
        'messageId',
        '_id'
    );

这将创建两个集合,一个errorCodeCache集合和一个messageCache集合。 combinedCache是errorCode文档的messageId和消息文档的_id上联接的结果。当我使用combinedCache检查时,结果combinedCache.data().length的大小远远超过1000。

但是,在对缓存执行查询之后,原始集合的大小将更改为结果的大小;换句话说,如果我的查询返回1个CouchDB文档,则combinedCache的大小现在为1。我在文档中找不到任何引用,该引用表明对集合的.find查询会改变结果。集合本身。在这种情况下,如何保留集合的大小?谢谢!

1 个答案:

答案 0 :(得分:0)

对于其他人,我设法使用此article来解决这个问题。

// branch just long enough to determine count of customers under 30 without filter affecting irishCustomers results
var lt30count = irishCustomers.copy().find({ ‘age’: { ‘$lt’ : 30 }).data().length;

因此,解决方案是添加.copy()以创建数据的临时副本,如果您不希望过滤器修改集合。

相关问题