如何对 minimongo 进行大量批量插入,而无需在每次插入时重新计算依赖查询 [英] How to do massive bulk inserts against minimongo without dependent queries getting recomputed on each insert

查看:30
本文介绍了如何对 minimongo 进行大量批量插入,而无需在每次插入时重新计算依赖查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在需要将大量文档插入到 minimongo 集合中,但其集合已经有一些依赖于它的查询(例如,游标绑定到模板助手)的情况下,如何有效地处理这种情况不锁定界面?

In a situation where one needs to insert a very large amount of documents into a minimongo collection, but whose collection already has a few queries depending on it (cursors bound to Template helpers for example), how does one efficiently approach this situation without locking up the interface?

推荐答案

直接针对 _collection.docs 插入,然后遍历 _collection.queries 并通过 失效>LocalCollection._recomputeResults().

Insert directly against _collection.docs, and then iterate over _collection.queries and invalidate via LocalCollection._recomputeResults().

示例:

_.each(bulk, function (doc) {
  MyCollection._collection.docs[doc._id] = doc;
});

_.each(MyCollection._collection.queries, function (query) {
  LocalCollection._recomputeResults(query);
});

这篇关于如何对 minimongo 进行大量批量插入,而无需在每次插入时重新计算依赖查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆