mongodb mapReduce for sailsjs

时间:2016-04-28 09:04:25

标签: node.js mongodb sails.js

我正在尝试根据创建时间对两个集合进行排序。我搜索了stackoverflow并找到了提到这个链接http://tebros.com/2011/07/using-mongodb-mapreduce-to-join-2-collections/的解决方案,你将mapReduce收集到另一个名为joined的Collection,然后使用给定的参数排序(在我的情况下是创建时间)。

现在的问题是我们如何在Sailsjs中使用mapReduce,我已经在这里提到了这个http://sailsjs.org/documentation/reference/waterline-orm/models/native

Pet.native(function(err, collection) {
  if (err) return res.serverError(err);

  collection.find({}, {
    name: true
  }).toArray(function (err, results) {
    if (err) return res.serverError(err);
    return res.ok(results);
  });
});

回调中的集合参数包含查找,创建等属性。集合参数是否具有 mapReduce 功能?因为在我的案例中它是未定义的。

除了打开原始连接并使用config / connection.js中打开的连接(默认连接)之外,是否有任何方法可以在Sailsjs中使用mapReduce。

或者更好的方法是根据特定属性对mongodb中的2个集合进行排序?

Sails v0.11.5,node v0.4.4.2

感谢。

0 个答案:

没有答案