You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my solution for the aggregate exercise, the problem is its giving this error-
var size = process.argv[2]; var url = "mongodb://localhost:27017/learnyoumongo"; var mongo = require("mongodb").MongoClient; mongo.connect(url, function(err, db){ if(err) throw err; var collection = db.collection("prices"); collection.aggregate({$match: {"size": size}}, {$group: {_id: "average"}, average:{$avg: "$price"}}).toArray(function(err, results){ if(err) throw err; console.log(Number(results[0].average).toFixed(2)); db.close(); }); });
error-
/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/exercises/aggregate/exercise.js:34
db.collection('prices').remove({}, function(err) {
^
TypeError: Cannot read property 'collection' of undefined
at Exercise. (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/exercises/aggregate/exercise.js:34:5)
at next (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:260:17)
at Exercise.end (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:266:5)
at Workshopper.end (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:191:12)
at Workshopper.done (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:323:19)
at Exercise. (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:149:14)
at /home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:136:16
at Exercise. (/home/ubuntu/.nvm/versions/node/v4.1.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/filecheck.js:10:14)
at FSReqWrap.oncomplete (fs.js:82:15)
I'm not even using .remove(), but it still gives the same error. I used the official solution but still getting the same error.
The text was updated successfully, but these errors were encountered:
This is my solution for the aggregate exercise, the problem is its giving this error-
var size = process.argv[2];
var url = "mongodb://localhost:27017/learnyoumongo";
var mongo = require("mongodb").MongoClient;
mongo.connect(url, function(err, db){
if(err) throw err;
var collection = db.collection("prices");
collection.aggregate({$match: {"size": size}}, {$group: {_id: "average"}, average:{$avg: "$price"
}}).toArray(function(err, results){
if(err) throw err;
console.log(Number(results[0].average).toFixed(2));
db.close();
});
});
error-
I'm not even using .remove(), but it still gives the same error. I used the official solution but still getting the same error.
The text was updated successfully, but these errors were encountered: