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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:59:37+00:00 2026-06-09T12:59:37+00:00

Is there a way to chain static constructor in mongoose ? In Rails its

  • 0

Is there a way to chain static constructor in mongoose ?

In Rails its the way to chain named_scopes

I have a special query to retrieve some data from mongo, but some time I have to apply a limit or to count them.

  • 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-09T12:59:38+00:00Added an answer on June 9, 2026 at 12:59 pm

    [Update] This feature has been removed.

    Mongoose has named scope capabilities, but there is an unresolved issue that may indicate they’re not working correctly; check the feature out and see if it works for you. (I will be doing this as well, when I get a chance, as it’s a really nice feature to have!)

    The following example code is taken from the named scope test at https://github.com/LearnBoost/mongoose/blob/master/test/namedscope.test.js.

    var UserNSSchema = new Schema({
        age: Number
      , gender: String
      , lastLogin: Date
    });
    
    UserNSSchema.namedScope('olderThan', function (age) {
      return this.where('age').gt(age);
    });
    
    UserNSSchema.namedScope('youngerThan', function (age) {
      return this.where('age').lt(age);
    });
    
    UserNSSchema.namedScope('twenties').olderThan(19).youngerThan(30);
    
    UserNSSchema.namedScope('male').where('gender', 'male');
    
    UserNSSchema.namedScope('female').where('gender', 'female');
    
    UserNSSchema.namedScope('active', function () {
      return this.where('lastLogin').gte(+new Date - _24hours)
    });
    
    mongoose.model('UserNS', UserNSSchema);
    
    UserNS.olderThan(20).find(function (err, found) { ... });
    UserNS.olderThan(40).active.male.find(function (err, found) { ... });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have the following, is there a way to chain them together, or
Is there way to copy a file into Plone with WebDAV and have Plone
Given an ActiveRecord method or named_scope chain, is there a way to return the
Is there a good way to chain methods conditionally in Ruby? What I want
So i was wondering if there is a way to method chain, when the
Is there a way to achieve the iTunes style modal view controller chain (see
Is there a way to chain this jQuery expression or improve it? All i
is there a way to chain queries in the "Play!" framework instead of manually
In bash, is there a way to chain multiple commands, all taking the same
I would like to know whether there's a way to chain methods on a

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.