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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:56:40+00:00 2026-06-17T04:56:40+00:00

The following TypeError cropped up in some old code. TypeError: Object #<Object> has no

  • 0

The following TypeError cropped up in some old code.

TypeError: Object #<Object> has no method 'findOne'

The Model that was affected recently had two new static methods defined and those methods referenced external models. After backing out the new static methods, I was able to determine the root cause to be the require statements of the external models. The pattern looks like the following:

var UserModel = require('./user');

var GroupSchema = new Schema({
    name: String,
    users: [{ type : Schema.ObjectId, ref: 'UserModel'}],
});

GroupSchema.statics.findSomeUsers = function(group, callback) {
    this.find({name : session_user._id}, function(err, groups) {
        UserModel.find({_id : {$in : group.users}}, function(err,patients) {
            // do magic
        });
    });
};

module.exports = mongoose.model('GroupModel', GroupSchema);

There is a code fragment in the application that calls GroupModel.findOne({name:’gogo’}) that leads to the TypeError. when I remove the require statement for the UserModel in the GroupSchema, app code works again.

Why does Javascript start to think findOne() is an instance method with the addition of the require statement?

  • 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-17T04:56:41+00:00Added an answer on June 17, 2026 at 4:56 am

    It’s known node.js issue. It means that you have looping require somewhere in your code and node.js forbids it.

    The right way to do it is by using mongoose.model method. So, instead of UserModel variable you shall use mongoose.model('UserModel'). So, when findSomeUsers will be called mondoose will fetch UserModel and invoke its find method.

    GroupSchema.statics.findSomeUsers = function(group, callback) {
        this.find({name : session_user._id}, function(err, groups) {
            mongoose.model('UserModel').find({_id : {$in : group.users}}, function(err,patients) {
                // do magic
            });
        });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code however am getting the error Uncaught TypeError: Object #<addThis>
I am getting the following error when running my code: Typeerror: lambda() takes exactly
I'm getting the following error, while using ExtJs MVC, Uncaught TypeError: Cannot call method
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
I wrote some JQuery code in an .js.coffee file and I get the following
All, I've got some code that I'm trying to debug and I used the
I tried the following: $.load(Views/chatBox.html).appendTo('body') Console Output: TypeError: $.load is not a function EDIT
Following code produces a nested array as a result for keys containing three items:
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to

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.