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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:25:44+00:00 2026-06-14T23:25:44+00:00

TypeError: Cannot call method ‘call’ of undefined at Array.MongooseArray._cast (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/mongoose/lib/types/array.js:78:15) at Object.map (native) at

  • 0
TypeError: Cannot call method 'call' of undefined
    at Array.MongooseArray._cast (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/mongoose/lib/types/array.js:78:15)
    at Object.map (native)
    at Array.MongooseArray.push (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/mongoose/lib/types/array.js:187:23)
    at module.exports (/Users/bodo/Documents/Repositories/EnabreNode/accounts/routes/me.js:29:27)
    at callbacks (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/express/lib/router/index.js:160:37)
    at Promise.module.exports (/Users/bodo/Documents/Repositories/EnabreNode/middleware/load_user.js:15:13)
    at Promise.addBack (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/mongoose/lib/promise.js:128:8)
    at Promise.EventEmitter.emit (events.js:96:17)
    at Promise.emit (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/mongoose/lib/promise.js:66:38)
    at Promise.complete (/Users/bodo/Documents/Repositories/EnabreNode/node_modules/mongoose/lib/promise.js:77:20)

I actually want to built a quite simple schema:

{
    username: "bodo",
    email: "info@example.com",
    contacts: [{ 
        user: { username: "john", email: "john@google.com" }, 
        messages: [
            { 
                sender: { username: "bodo", email: "info@example.com" },
                receiver: { username: "john", email: "john@google.com" },
                body: "How are you these days?"
            },
            { 
                sender: { username: "john", email: "john@google.com" },                                       
                receiver: { username: "bodo", email: "info@example.com" },
                body: "I am totally fine?"
            } 
        ]
    }]
};

The contacts attribute contains a contacts subdocument which holds the user object of the actual contact (as reference) and later on some meta data like hasAcceptedContactRequest, contactSince, etc.
Additionally I also save messages subdocs which are from a chat. These message subdocs contain the message as body attribute and who has send or received it. The sender and receiver are again references to a full user object which can be populated.

So much in theory. I now have created these schemas:

UserSchema

var Mongoose = require('mongoose');
var ContactSchema = require('./contact');

var UserSchema = new Mongoose.Schema({

    username: { 
        type: String, 
        index: { unique: true, sparse: true }, 
        required: true, lowercase: true, trim: true
    },

    email: {
        type: String,
        index: { unique: true, sparse: true }, 
        required: true, lowercase: true, trim: true
    },

    contacts: [ContactSchema]

});

module.exports = Mongoose.model('User', UserSchema, 'Users');

ContactSchema

var Mongoose = require('mongoose');
var MessageSchema = require('./message');

var ContactSchema = new Mongoose.Schema({

    user: {
        ref: "User",
        type: Mongoose.Schema.Types.ObjectId
    },

    messages: [MessageSchema]

});

module.exports = ContactSchema;

MessageSchema

var MessageSchema = new Mongoose.Schema({

    body: {
        type: String
    },

    sender: {
        ref: "User",
        type: Mongoose.Schema.Types.ObjectId
    },

    receiver: {
        ref: "User",
        type: Mongoose.Schema.Types.ObjectId
    }

});

module.exports = ContactSchema;

That is the route

app.put('/me', loadUser, function(req, res, next) {
    var user = req.user;
    var body = req.body;

    if (body.contacts) {
        body.contacts.forEach(function(contact) {
            user.contacts.push({ user: contact });
        });
    }

    console.log(req.user);

    user.save(function(err, user) {
        if (err) return next(err);
        res.send(200);
    });
});

Solution:
As johnyHK mentioned there was a problem using the module system of node. I have accidentally
exported the schemas as models. You now see the corrected examples above. So they should work.

  • 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-14T23:25:45+00:00Added an answer on June 14, 2026 at 11:25 pm

    Assuming the order of your schema definitions is the same in your code, you need to reorder them so that the referenced schemas are fully defined when used.

    So that would be:

    1. MessageSchema
    2. ContactSchema
    3. UserSchema
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this error Uncaught TypeError: Cannot call method 'create' of undefined of
Uncaught TypeError: Cannot call method 'replace' of undefined highlight_termgithub.tokeninput.js:538 $.TokenList.selected_dropdown_itemgithub.tokeninput.js:557 e.extend.eachjquery.min.js:16 populate_dropdowngithub.tokeninput.js:556 $.TokenList.ajax_params.successgithub.tokeninput.js:670 f.extend._Deferred.e.resolveWithjquery.min.js:16
I'm getting this error: Uncaught TypeError: Cannot call method 'match' of undefined in my
I'm getting the following error, while using ExtJs MVC, Uncaught TypeError: Cannot call method
I'm getting an error that says Uncaught typeError: cannot call method 'hover' of null
I have in console(Ctrl+J) chorme as error: Uncaught TypeError: Cannot call method 'reverse' of
I'm getting the error: Uncaught TypeError: Cannot read property 'constructor' of undefined When declaring
I'm getting an an error TypeError: Cannot read property 'style' of undefined I'd be
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Why does any(['','foo']) raise the exception TypeError: cannot perform reduce with flexible type I

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.