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

281
Vistas
How to query field equals empty array?

I have an array field in my collection which have value with properties or empty value as "[]"

For fetching the documents having empty "[]" value in mongodb i use

db.getCollection('collection').find({"ArrayFieldName":{$eq:[]}})

This gives me result as expected. But when i try to form this query in the C# using mongodb driver i couldnt get the expected Result.

I tried, filterBuilder.Eq("ArraryFieldName", "[]") and filterBuilder.Eq("ArraryFieldName", new ArraryClassName(){})

Need help with C# filter builder to specify $eq:[] for arrary field.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

An instance of ArraryClassName clearly won't work because it's not an array instance - it's a single object. Likewise "[]" won't work because it's a string.

You can check directly translate your CLI query to this filter:

Builders<BsonDocument>.Filter.Eq<BsonArray>("ArraryFieldName", new BsonArray())

Though if you simply want to check that the existing array is empty, you can use this filter instead:

Builders<BsonDocument>.Filter.Size("ArraryFieldName", 0)

P.S. I would strongly suggest using C# data models as it makes everything much easier to work with.

Also, you have called your field ArraryFieldName (notice the extra r at the end of Array). If you don't have existing data with this misspelled property name, you might want to correct the spelling.

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