如何在猫鼬的聚合中执行 $out?

如何在猫鼬的聚合中执行 $out?

问题描述:

我查找了有关如何在聚合中执行 $out 的文档,但没有找到.

I looked for documentation of how to perform $out in an aggregation but I didn't find.

这是我的查询:

Top.aggregate([
  {$sort: {created: -1}},
  {$group: {_id:'$location', title:{$push: '$title'}}},
  {$project: {location: '$location', mostRecentTitle: '$title'}},
  {$out: "aggr_out"}
]).exec(function(err, docs) {  console.log(docs); console.log(err) });

架构:

var schema = mongoose.Schema({
  location: {type: String},
  title: {type: String},
  created: {type: Number, default: Math.floor(new Date() / 1000)}
})

可能兼容mongodb 3.0.x

It might to be compatible with mongodb 3.0.x

我检查了数据库,它似乎用条目创建了一个类似于 'aggr_out' 的新集合.我认为它已解决.

I checked the database and it seems to create a new collection something like 'aggr_out' with the entries. I'm considering it as solved.