Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

290
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda