Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8822925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:13:40+00:00 2026-06-14T06:13:40+00:00

I’m running through the mongoose quickstart and my app keeps dying on fluffy.speak() with

  • 0

I’m running through the mongoose quickstart and my app keeps dying on fluffy.speak() with the error TypeError: Object { name: 'fluffy', _id: 509f3377cff8cf6027000002 } has no method 'speak'

My (slightly modified) code from the tutorial:

"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);
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:13:41+00:00Added an answer on June 14, 2026 at 6:13 am

    When you call db.model, the model is compiled from your schema. It’s at that point that schema.methods are added to the model’s prototype. So you need to define any methods on the schema before you make a model out of it.

    // ensure this method is defined before...
    kittySchema.methods.speak = function() {
        var greeting = this.name ? "Meow name is" + this.name : "I don't have a name";
        console.log(greeting);
    }
    
    // ... this line.
    var Kitten = db.model('Kitten', kittySchema);
    
    // methods added to the schema *afterwards* will not be added to the model's prototype
    kittySchema.methods.bark = function() {
        console.log("Woof Woof");
    };
    
    (new Kitten()).bark(); // Error!  Kittens don't bark.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
i got an object with contents of html markup in it, for example: string
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.