• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

126
Vistas
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 Respuestas
Responde la pregunta

0

You can try something like this:

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

about 3 years ago · Juan Pablo Isaza Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda