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

  • SEARCH
  • Home
  • 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 8378029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:49:39+00:00 2026-06-09T15:49:39+00:00

EDIT/ANSWER: this works fine in mongoose >= 3.0 also I have a mongoose schema

  • 0

EDIT/ANSWER: this works fine in mongoose >= 3.0 also

I have a mongoose schema that looks like so:

mongoose = require 'mongoose'
ObjectId = mongoose.Schema.ObjectId

VehicleSchema = new mongoose.Schema
  make: String
  model: String
  year: Number
  body: String
  fuel: String
  transmission: String
  parts: [ { type: ObjectId, ref: 'Part' } ]

VehicleSchema.virtual('display_name').get ->
  return this.make + ' ' + this.model + ' ' + this.year

VehicleModel = mongoose.model 'Vehicle', VehicleSchema

module.exports =
  Schema: VehicleSchema
  Model: VehicleModel

I add ‘parts’ to the vehicle like this:

Vehicle.Model.findById id, (err, vehicle) ->
      unless err
        part = new Part.Model {
          ...details
        }
        part.save (err, doc) ->
          unless err
            vehicle.parts.push doc
            vehicle.save()
          else
            console.error err

which seems to work:

{ "_id" : ObjectId("5027bd4340b00b897a000002"), "body" : "car", "fuel" : "unleaded", "make" : "stackover", "model" : "modelname", "parts" : [ ObjectId("5027bd5140b00b897a000006") ], "transmission" : "manual", "year" : 21212 }

but when I try and populate the parts:

Vehicle.Model
  .findById(vehicle_id)
  .populate('parts')
  .exec (err, doc) ->
    if err
      console.error err
    else
      console.error doc

I get an error:

TypeError: Property 'model' of object { parts: [] } is not a function at model.populate [as _populate]

What gives? I had another model/controller combination that was almost a carbon copy of this that worked perfectly (I’ve pretty much find/replaced the nouns and it still breaks, seriously freaking out here!)

  • 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-09T15:49:41+00:00Added an answer on June 9, 2026 at 3:49 pm

    I think its likely that the name “model” is used internally, and the definition of VehicleSchema is clobbering something that mongoose expects to be a function with the “String” type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: See my answer below--> I am wanting to have a view that when
FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
This function works fine. It scrolls the body to a desired container's offset function
There is probably a really simple answer for this ... I have a project
EDIT The bare-bones version of this question is, if I have some object o
I have a Gallery that works perfectly, except only the first element is ever
Here is the code that works fine : template<typename... Args> struct count; template<> struct

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.