Mongodb 猫鼬聚集不起作用

Mongodb 猫鼬聚集不起作用,mongodb,mongoose,Mongodb,Mongoose,Mongodb 2.2.0和3.3.1 我正在尝试运行以下查询: var db = mongoose.connect('localhost', 'test', '27017').connection; var testSchema = new Schema; var tr= db.model('tests', testSchema); tr.aggregate({'$group':{'_id':'$test_id', 'average':{$avg:'$tes_tscore'}}}) 以

Mongodb 2.2.0和3.3.1

我正在尝试运行以下查询:

var db = mongoose.connect('localhost', 'test', '27017').connection;
var testSchema = new Schema;
var tr= db.model('tests', testSchema);  

tr.aggregate({'$group':{'_id':'$test_id', 'average':{$avg:'$tes_tscore'}}})
以下错误不断弹出:

TypeError: Object function model(doc, fields, skipId) {
    if (!(this instanceof model))
      return new model(doc, fields, skipId);
    Model.call(this, doc, fields, skipId);
  } has no method 'aggregate'  
mongoose是否还不支持聚合,或者我的代码缺少什么


**
测试
集合有1000多个文档。运行
tr.find(…console.log(…)
返回所需的文档。

聚合在3.x中受支持。示例中的代码看起来不错,但不知何故
tr
引用了模型()方法而不是模型实例。如果您能够一致地重新创建此问题,请打开一个包含要运行的确切代码的票证,我们将修复它


聚合在3.x中受支持。您的示例中的代码看起来不错,但不知何故,
tr
引用的是model()方法,而不是模型实例。如果您能够一致地重新创建此问题,请打开一个包含要运行的确切代码的票证,我们会将其修复

我解决了它

在脚本中放置
console.log(mongoose.version);
显示为过时版本(3.0.2)

我重新浏览了这些模块(这次很小心),删除并重新安装了
mongoose

3.3.1版和
aggregate
现在可以使用了

aggregate
在3.1.0版上线

我解决了它

在脚本中放置
console.log(mongoose.version);
显示为过时版本(3.0.2)

我重新浏览了这些模块(这次很小心),删除并重新安装了
mongoose

3.3.1版和
aggregate
现在可以使用了


aggregate
已上线v.3.1.0

您可以使用db.runCommand(“aggregate”:collectionName,“pipeline”:)进行聚合,而无需使用聚合辅助程序,使用db.runCommand(“aggregate”:collectionName,“pipeline”:)我可以始终如一地重新创建此问题。不仅使用此模型,还可以使用其他模型。我将提交一张票证。我可以始终如一地重新创建此问题。不仅使用此模型,还可以使用其他模型。我将提交一张票证。