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

127
Vistas
can't find in array that references another collection mongoose

I have this data whose 'contacts' field references another collection:

{
   "_id":{"$oid":"61549125765ffb0f0477678d"},
   "contacts":[{"$oid":"61549123765ffb0f04776787"}],
   "username":"petete",
   "phoneNumber":"+222222222222",
   "__v":{"$numberInt":"0"},
   "socketId":"CEvkxvonNfXyhZMFAAAJ"
}

If i find it with populate(), i get this:

 {
      contacts: [  //i want to show this array
        {
          contacts: [Array],
          _id: 61549123765ffb0f04776787,
          username: 'tachancka',
          phoneNumber: '+111111111111',
          __v: 0,
          socketId: 'C3srKMQB80tIrC2jAAAK'
        }
      ],
      _id: 61549125765ffb0f0477678d,
      username: 'petete',
      phoneNumber: '+222222222222',
      __v: 0,
      socketId: 'CEvkxvonNfXyhZMFAAAJ'
 }

So i need to find the first 'contacts' array by id. I tried with this code, but it returns null:

User.findOne({_id: userLoggedId, 'contacts._id': contactId}).populate({
   path: 'contacts',
   model: 'User'
})

And these are my consts:

userLoggedId = '61549125765ffb0f0477678d'
contactId = '61549123765ffb0f04776787'

What am i doing wrong?

about 4 years ago · Juan Pablo Isaza
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