我将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
查询会改变结果。集合本身。在这种情况下,如何保留集合的大小?谢谢!
答案 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()
以创建数据的临时副本,如果您不希望过滤器修改集合。