0
我试图将数据插入到mongodb数据库中。将用户数据插入到mongodb数据库中
我能够提交用户数据,并显示它...
app.get('/process_get', function (req, res) {
response = {
first_name:req.query.firstName,
last_name:req.query.lastName,
username:req.query.userName,
password:req.query.password,
email:req.query.email
};
console.log(response);
res.end(JSON.stringify(response));
})
我再开用MongoDB的连接,创造了“测试”收集成功...
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) { return console.dir(err); }
if(!err) { console.log("MongoDB server is connected!") }
var collection = db.collection('test');
})
我试过“collection.insert({name:req.query.firstName});” 但这显然没有工作,因为没有“请求”。我如何使输入全球 ,所以我可以简单地插入它们?