财产“集合”冉这个问题,而这样做https://www.freecodecamp.com/challenges/store-data-in-mongodb使用MongoDB的:类型错误:无法读取的不确定
错误信息被
swyx:~/workspace $ learnyoumongo run find.js
/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/server.js:231
process.nextTick(function() { throw err; })
^
TypeError: Cannot read property 'collection' of undefined
at Exercise.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/exercises/find/exercise.js:37:5)
at next (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:271:17)
at Exercise.end (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:277:5)
at Workshopper.end (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:191:12)
at Workshopper.done (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:323:19)
at Exercise.<anonymous> (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:160:14)
at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:147:16
at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/exercises/find/exercise.js:20:21
at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/mongo_client.js:238:20
at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/db.js:242:14
还有其他类似的问题在这里,但他们都不是描述此确切的问题
供参考,这是上
var mongo = require('mongodb').MongoClient
var age = process.argv[2]
var url = 'mongodb://localhost:27017/learnyoumongo'
mongo.connect(url, function(err, db) {
if (err) throw err
var parrots = db.collection('parrots')
parrots.find({
age: {
$gt: +age
}
}).toArray(function(err, docs) {
if (err) throw err
console.log(docs)
db.close()
})
})
的(有效的)代码我是运行它
我发现我自己的解决方案,并贴在下面,以帮助人们在未来 – swyx