node.js - LokiJs 集合上的芒果查询更改了集合的大小
问题描述
我将 LokiJs 用作应用程序的内存缓存,该应用程序将数据存储在 CouchDB 中并允许通过 NodeJS 服务器进行检索。根据有关构建查询的文档,我的查询结果被分配给一个结果集对象:
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
是错误messageId
代码文档和_id
消息文档的连接结果。当combinedCache
我使用combinedCache.data().length
.
但是,在我对缓存执行查询后,原始集合的大小更改为结果的大小;换句话说,如果我的查询返回 1 个 CouchDB 文档,combinedCache
则 的大小现在为 1。我在文档中找不到任何引用说明.find
对集合的查询会改变集合本身的结果。如果是这种情况,如何保留集合的大小?谢谢!
解决方案
对于看到这一点的其他人,我设法使用这篇文章弄清楚了。
// 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()
如果不希望过滤器修改集合,就添加创建数据的临时副本。
推荐阅读
- python - 获取箱线图中标记的值
- azure-devops - Azure DevOps 中的 IP 白名单
- sequelize.js - 如何从列中获取不包括某些行的行,这些行的 Id 保存在另一个表中
- r - 如何在R中将具有多个工作表的多个excel文件组合成一个具有多个工作表的excel文件
- css - CSS @document Safari Alternative(自定义样式表中特定于站点的 CSS 覆盖)
- mongodb - 如何查看哪些查询正在使用 MongoDB 中的索引?
- javascript - 状态未更新。当我记录数据时,它显示“刚刚评估的值低于”
- reactjs - 如何将 D3.js 代码转换为反应代码
- javascript - 如何使用云功能在 Firebase 中获取实时数据库?
- wordpress - 复选框不可用 - 联系表格 7 - Wordpress - MDBootstrap