我正在使用Node.js运行这段代码:
var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://${server}:27017/${db}";
var username = '${user_name}';
var password = '${password}'
// Connect to the db
MongoClient.connect(url, function(err, db) {
if(!err) {
console.log("successfully connected to the database");
}else{
console.log("Error on connecting... aborting and exiting");
return console.dir(err);
throw err;
}
db.authenticate(username, password, function(err, res) {
var startId = 7882;
var userCount = 100;
var num = 235;
var baseGeologOrig = db.collection('geologs').find({user_id:279, created_at:{$gte:new Date("2015-01-31"), $lte:new Date("2015-02-02")}}).limit(1227);
var baseGeolog = [];
baseGeologOrig.forEach(function (obj) {delete obj._id;baseGeolog.push(obj);});
// callback
console.log("Reached here...!");
console.log(baseGeologOrig);
现在当我运行这段代码时,我收到以下错误:
TypeError: undefined is not a function
at /home/Scripts/node_modules/mongodb/lib/cursor.js:696:15
at handleCallback (/home/Scripts/node_modules/mongodb/lib/utils.js:95:12)
at /home/Scripts/node_modules/mongodb/lib/cursor.js:662:22
at handleCallback (/home/Scripts/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:244:5)
at /home/Scripts/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:659:22
at queryCallback (/home/Scripts/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:267:14)
at Callbacks.emit (/home/Scripts/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:95:3)
at null.messageHandler (/home/Scripts/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:243:23)
at Socket.<anonymous> (/home/Scripts/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:262:22)
at Socket.emit (events.js:107:17)
我测试了它,发现这个问题是我最后一行代码,任何想法如何解决?
先谢谢了!
答案 0 :(得分:0)
你可能在var baseGeologOrig=
本身得到一个未定义的值这就是你得到obj值未定义的原因请检查。
请吊起记录baseGeologOrig