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

350
Vistas
Mongo: Query for documents based on nested array length

I have a document structure that looks like this:

{
key1:value1,
key2:value2,
key3: [
    index0: objectID(...),
    index1: [
          index0: objectID(...)
         ]
      ]
}

I know you can access arrays using Mongo's dot notation, but I am trying to build a query that only selects all records where key3.index1 length is greater than zero.

All documents in this collection will have key3 and key3 will always have an array at index1. In some cases this array will not be empty.

So far I've tried something like this: db.collection.find({$where: "this.key3.1.length > 0"}) but this doesn't work.

How can I query for documents using the length of a nested array?

EDIT: Sample Data

{
    "_id" : ObjectId("57c98fe77fe6f8009401b5d7"),
    "arrayOfData" : [ 
        ObjectId("57c98fe87fe6f8009401b5d8"), 
        [ 
            ObjectId("57c98fe87fe6f8009401b5d9")
        ]
    ]
}

The above is the relevant snippet from the document structure. All documents will have this, in some cases the nested array will be empty, in some cases it will not.

over 4 years ago · Santiago Trujillo
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