mongoose document Getting Started it is wrong!!!!!

Created on 1 May 2018  ·  4Comments  ·  Source: Automattic/mongoose

你好,我在查看 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.

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?

All 4 comments

@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!

Was this page helpful?
0 / 5 - 0 ratings