你好,我在查看 mongoose 文档,使用 http://mongoosejs.com/docs/index.html 的 案例 ,结果是错误的。
Hello, I am see mongoose documentation, use http://mongoosejs.com/docs/index.html's case, the result is wrong.
我按照文档的代码,结果保存的结果是 空的
I follow the document's code, and the result is empty.
var mongoose = require('mongoose')
var kittySchema = mongoose.Schema({
name: String
});
kittySchema.methods.speak = function () {
var greeting = this.name
? "Meow name is " + this.name
: "I don't have a name";
console.log(greeting);
}
var Kitten = mongoose.model('Kitten', kittySchema);
module.exports = Kitten
const Kitten = require('../models/Kitty')
add () {
let fluffy = new Kitten({ name: 'fluffy' });
return new Promise((resolve, reject) => {
fluffy.save(function (err, fluffy) {
if (err) return reject(err)
resolve(fluffy)
})
})
}
fluffy 的 结果是空的
fluffy is result is empty.
@BengBu-YueZhang
Your example doesn't show a connection to any mongodb servers. Are you calling mongoose.connect('mongodb://host/db')
in your code?
对不起,问题解决了,请关闭
Sorry, the problem is solved. Please close it.
@lineus
对不起,问题解决了,请关闭
Sorry, the problem is solved. Please close it.
@BengBu-YueZhang I'm glad it's working!
Most helpful comment
@BengBu-YueZhang
Your example doesn't show a connection to any mongodb servers. Are you calling
mongoose.connect('mongodb://host/db')
in your code?