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 6801295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:04:57+00:00 2026-05-26T19:04:57+00:00

Based on this example (which works): var Comment = new Schema(); Comment.add({ title :

  • 0

Based on this example (which works):

var Comment = new Schema();

Comment.add({
    title : { type: String, index: true }
  , date : Date
  , body : String
  , comments : [Comment]
});

I wanted to create a CoffeeScript version

mongoose = require 'mongoose'
Schema = mongoose.Schema

Person = new Schema
Person.add
  mother: Person
  father: Person

However it returns an error and I don’t understand why

TypeError: undefined is not a function
    at CALL_NON_FUNCTION_AS_CONSTRUCTOR (native)
    at Function.interpretAsType (/path/node_modules/mongoose/lib/schema.js:202:10)
    at Schema.path (/path/node_modules/mongoose/lib/schema.js:162:29)
    at Schema.add (/path/node_modules/mongoose/lib/schema.js:110:12)
    at Object.<anonymous> (/path/Models/test.coffee:6:10)
    at Object.<anonymous> (/path/Models/test.coffee:10:4)
    at Module._compile (module.js:411:26)
    at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script.js:57:25)
    at /usr/local/lib/node_modules/coffee-script/lib/command.js:147:29
    at /usr/local/lib/node_modules/coffee-script/lib/command.js:115:26

EDIT: Okay, I found out that it doesn’t work when Person isn’t an array (in brackets), but why?

  • 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-05-26T19:04:58+00:00Added an answer on May 26, 2026 at 7:04 pm

    Embedded documents can only exist as items in an array. That is by design, you can ask the authors for their reasons 🙂

    You might want to use a DBRef:

    Person = new Schema
      mother: { type: Schema.ObjectId, ref: 'Person' }
      father: { type: Schema.ObjectId, ref: 'Person' }
    

    (notice you don’t need the add call)

    See the docs for populate/DBRef.

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

Sidebar

Related Questions

Based on this , how would you make ignoring parameters more succint? var m
This question is based on this thread . Is [---] a comment in Git
Hope that someone out there can help with this! I'll give an example based
Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine() : (Note that
Using this question as the base is there an alogrithm or coding example to
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I don't want to litter my ready stuff waiting for
Based on this article , it seems like SO is using Javascript OpenID Selector
Based on this question I understand the purpose of the construct in linking C
This question is based on this thread . I am interested in how Git

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.