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

135
Vistas
How I can find if string exists inside mongodb Array

I am trying to find document based on profileID in MongoDB. I want to check if string postid exists in array or not. How I can do that? I tried $all.

Mongo data:

{
  "profileId": "abc",
  "likedPosts": [
    'post1',
    'post2'
  ]
}

Trying to find if post1 exists in array:

findOne({
  profileId
}, {
  likedPosts: {
    $all: ['post1']
  }
}, )
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want to check if a string exists in an array field you can simply do:

findOne({
  profileId,
  likedPosts: 'post1'
  }
}, )

Docs

Also you might notice i have made the whole query as the first parameter. The second parameter is usually the callback to run, once the query has executed.

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