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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:18:59+00:00 2026-05-27T02:18:59+00:00

I have an array of _ids and I want to get all docs accordingly,

  • 0

I have an array of _ids and I want to get all docs accordingly, what’s the best way to do it ?

Something like …

// doesn't work ... of course ...

model.find({
    '_id' : [
        '4ed3ede8844f0f351100000c',
        '4ed3f117a844e0471100000d', 
        '4ed3f18132f50c491100000e'
    ]
}, function(err, docs){
    console.log(docs);
});

The array might contain hundreds of _ids.

  • 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-27T02:19:00+00:00Added an answer on May 27, 2026 at 2:19 am

    The find function in mongoose is a full query to mongoDB. This means you can use the handy mongoDB $in clause, which works just like the SQL version of the same.

    model.find({
        '_id': { $in: [
            mongoose.Types.ObjectId('4ed3ede8844f0f351100000c'),
            mongoose.Types.ObjectId('4ed3f117a844e0471100000d'), 
            mongoose.Types.ObjectId('4ed3f18132f50c491100000e')
        ]}
    }, function(err, docs){
         console.log(docs);
    });
    

    This method will work well even for arrays containing tens of thousands of ids. (See Efficiently determine the owner of a record)

    I would recommend that anybody working with mongoDB read through the Advanced Queries section of the excellent Official mongoDB Docs

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

Sidebar

Related Questions

Given an array of ids $galleries = array(1,2,5) I want to have a SQL
I have an array of apps with ids and categories like this: [apps] =>
Is there an easy way to get several noads loaded into an array? I
I have a canvas Facebook application, I have all user friends in JS array,
I've got an array of 200 numbers (item ids) and I want to get
I have a TV named Kategorie and I want a list of all resources
I have 2 tables. One (artWork) with all the data I want to pull
I'm trying to do something like this to preload all data, so I don't
I have an array of employee ids: 34 , 35, 40, 67, 54 and
I have an array of products IDs and I need to find the IDs

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.