Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
How to select only products with ids from ids array. MongoDB

I'm getting all products and populate the category with mongoDB. Also I have array with category ids and I want to get only products, that have that ids in category object. How to select only this products?

arr of ids [ '615e94cab42d2274f0481232' ]

arr of products [
  {
    _id: new ObjectId("615e945cb42d2274f0481211"),
    image: '',
    category: { _id: new ObjectId("615da90b689b8ef91fa90afd"), name: 'Разное' },
    name: '435пукп',
    type: 'В упаковке',
    piecesPerPackage: 2,
    pricePerPiece: 1,
    pricePerPackage: 2,
    weight: 12,
    description: 'вапвап'
  },
  {
    _id: new ObjectId("615eaa08f68e788c63817641"),
    image: '',
    category: { _id: new ObjectId("615e94cab42d2274f0481232"), name: '2' },
    name: '2',
    type: 'В упаковке',
    piecesPerPackage: 2,
    pricePerPiece: 2,
    pricePerPackage: 2,
    weight: 2,
    description: '2'
  }
]

async sortCatalog(arr) {
        const products = await CatalogModel.find().lean()
            .populate("category", "name").select('-__v');
        console.log("arr of ids", arr)
        console.log("arr of products", products)
    }

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use category._id to find it.

await CatalogModel.find({'category._id':new ObjectId("615e94cab42d2274f0481232")})
about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda