• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

125
Views
How will I choose many objects with mongoose?

For example, I have

[
  { name: "John" },
  { name: "Mike" },
  { name: "Homer" },
  { name: "Bart" },
  { name: "Dmitry" },
  { name: "Dan" }
]

How will I choose many objects with mongoose, if I use .limit(2) I will get [{ name: "John" }, { name: "Mike" }], I need to choose [{ name: "Bart" }, { name: "Dmitry" }]. In default JS this method looks like .slice(3,5). How will I do it with mongoose?

about 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can try something like this:

Model.find({name: {$in: ["Bart", "Dmitry"]}});

about 3 years ago · Juan Pablo Isaza Report

0

You can achieve this in mongodb by using skip(3).limit(2).

In Mongoose you can achieve this with myModel.find({}, 'name', {skip: 3, limit: 2}), you just have to insert values of skip and limit you want in third parameter of find.

Here's documentation with an example of skip and here's a link to a more popular answer of similar problem.

Edit: Note that this is a short-sighted solution, you should use something else for large or changing database.

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error