TypeError: Objekt ist nicht eine Funktion in die Verwendung von MongoDB mit Node.js

Ging ich durch Frage und er fragte mich, berechnen der minimale Wert der Punktzahl für jedes Kind in der Klasse. Ich schrieb das folgende source-code.

Ich bin mit Mongo 2.6.9 und Knoten v0.10.25 und ubuntu 14.04 LTS

var MongoClient=require('mongodb').MongoClient;
var server=require('mongodb').Server;

var mongoclient=new MongoClient(new server("localhost",27017));

mongoclient.connect("mongodb://localhost:27017/",function(err,db){
if(err) throw err;

var db=mongoclient.db('school');

cursor=db.collection('students').aggregate(
[
  {$match : {"scores.type" : "homework"}},
  {$unwind:"$scores"},
  {$group : {_id : '$name',
  'minimum' : { $min :"$scores.score"  }
}
}
]);
});

Diese zusammengesetzte Abfrage bei der Ausführung mit Knoten app.js gibt diese Fehler

/home/oroborus/node_modules/mongodb/lib/mongodb/connection/base.js:246
        throw message;      
              ^
TypeError: object is not a function
    at /home/oroborus/node_modules/mongodb/lib/mongodb/collection/aggregation.js:317:7
    at /home/oroborus/node_modules/mongodb/lib/mongodb/db.js:1195:7
    at /home/oroborus/node_modules/mongodb/lib/mongodb/db.js:1903:9
    at Server.Base._callHandler (/home/oroborus/node_modules/mongodb/lib/mongodb/connection/base.js:453:41)
    at /home/oroborus/node_modules/mongodb/lib/mongodb/connection/server.js:488:18
    at MongoReply.parseBody (/home/oroborus/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
    at null.<anonymous> (/home/oroborus/node_modules/mongodb/lib/mongodb/connection/server.js:446:20)
    at EventEmitter.emit (events.js:95:17)
    at null.<anonymous> (/home/oroborus/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:207:13)
    at EventEmitter.emit (events.js:98:17)

Was nach mir kommt von der Aggregat-Funktion. Aber wenn ich die gleiche Abfrage in der mongo-terminal erhalte ich eine korrekte Ausgabe.

cursor=db.students.aggregate( [   {$match : {"scores.type" : "homework"}},   {$unwind:"$scores"},   {$group : {_id : '$name', 'minimum' : {   $min :"$scores.score"  } } } ]);
{ "_id" : "Myrtle Wolfinger", "minimum" : 35.99397009906073 }
{ "_id" : "Gennie Ratner", "minimum" : 34.50565589246531 }
{ "_id" : "Nobuko Linzey", "minimum" : 19.27081566886746 }
{ "_id" : "Flora Duell", "minimum" : 40.68238966626067 }
{ "_id" : "Shin Allbright", "minimum" : 52.68629677727286 }

Ques - Was und wo ist der Fehler und wie beheben Sie es .


Danke.

InformationsquelleAutor Saras Arya | 2015-04-04
Schreibe einen Kommentar