在MongoDB中以批量模式执行功能

时间:2017-05-22 14:07:30

标签: java mongodb bulkinsert

我有一个非常特殊的用例来实现。为了提高将信息写入MongoDB Collection的过程的性能,我尝试使用bulk writes。要求的“特殊”方面是某些操作类似于以下内容:

// Firt of all, try the update
var result = db.test.update(
  { /* Omissis*/ },
  {$inc :{ /* Omissis */ }},
  {upsert: false}
);
// If the update do not succeed, then try to insert the document
if (result.nModified === 0) {
  try {
    db.test.insert(/* Put here the whole document */);
  } catch (err) {
    console.log(err);
  }
  // Here we are sure that the document exists.
  // Retry to execute the update statement
  db.test.update(/* Same update as above */);
}

这些陈述应按既定顺序和给定逻辑执行。

如果我在MongoDB中定义了一个函数,哪个正文由上面的代码表示,是否可以在批量模式下调用它?如果可能,给定的解决方案应该是可以用Java驱动程序重现的东西。

感谢所有人。

0 个答案:

没有答案