Я запускаю mongoose quickstart, и мое приложение продолжает умирать на fluffy.speak()
с ошибкой TypeError: Object { name: 'fluffy', _id: 509f3377cff8cf6027000002 } has no method 'speak'
Мой (слегка модифицированный) код из учебника:
"use strict";
var mongoose = require('mongoose')
, db = mongoose.createConnection('localhost', 'test');
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
var kittySchema = new mongoose.Schema({
name: String
});
var Kitten = db.model('Kitten', kittySchema);
var silence = new Kitten({name: 'Silence'});
console.log(silence.name);
kittySchema.methods.speak = function() {
var greeting = this.name ? "Meow name is" + this.name : "I don't have a name";
console.log(greeting);
};
var fluffy = new Kitten({name: 'fluffy'});
fluffy.speak();
fluffy.save(function(err) {
console.log('meow');
});
function logResult(err, result) {
console.log(result);
}
Kitten.find(logResult);
Kitten.find({name: /fluff/i }, logResult);
});