我试图通过快递应用程序与mongodb进行“简单”连接,代码如下:
var express = require("express");
var http = require("http");
var mongoose = require("mongoose");
//database connections
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost:27017/contactlist');
var contactSchema = new mongoose.Schema({
name: String,
email: String,
number: String
});
var Contact = mongoose.model("Contact", contactSchema);
exports.getcontactlist = function (request, response) {
console.log("connecting to mongo again...");
Contact.find({ }, function (err, docs) {
console.log(docs);
response.send(docs);
});
};
返回的结果始终为“[]”。
请有人指出我正确的方向吗?
修改::
是的,数据库已填充