var mongoose = require(“mongoose”); var kittySchema = mongoose.Schema({ name: String, age: String }); var Kitten = mongoose.model("jj", kittySchema); mongoose.connect("mongodb://localhost/nodeTest", function (err) { if (!err) { console.log(“connected to mongoDB”); } else { throw err; } }); Kitten.find(function(err, data){ console.log(data); });
查出来的是[] 是什么原因啊? 我不知道应该在哪里体现我的表名 jj
我建议你试试这样 var mongoose = require(“mongoose”); var kittySchema = mongoose.Schema({ name: String, age: String }); mongoose.model("jj", kittySchema); var db = mongoose.connect("mongodb://localhost/nodeTest", function (err) { if (!err) { console.log(“connected to mongoDB”); } else { throw err; } }); var Kitten = db.model(‘jj’); Kitten.find(function(err, data){ console.log(data); });