我尝试使用find
andfindOne
并且两者都没有返回文档。在返回时返回find
一个空数组。在这两种情况下也是如此。findOne
null
err
null
这是我的连接:
function connectToDB(){
mongoose.connect("mongodb://localhost/test"); //i have also tried 127.0.0.1
db = mongoose.connection;
db.on("error", console.error.bind(console, "connection error:"));
db.once("open", function callback(){
console.log("CONNECTED");
});
};
这是我的架构:
var fileSchema = mongoose.Schema({
hash: String,
type: String,
extension: String,
size: String,
uploaded: {type:Date, default:(Date.now)},
expires: {type:Date, default:(Date.now()+oneDay)}
});
var Model = mongoose.model("Model", fileSchema);
我的查询在这里:
Model.find({},function(err, file) {
console.log(err)
console.log(file);
});
我可以将内容上传到数据库并通过RockMongo查看它们,但之后我无法获取它们。这是我第一次使用 MongoDB,所以我认为我只是缺少一些基础知识。任何朝着正确方向的推动都会很棒!