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

237
Visualizações
Lambda where fails but string where works

Using the old MongoDB driver, I was able to perform the following query:

Query.Where("this.plan.sstats.used < this.plan.sstats.available")

But with the new one, I'm forced to write this:

builder.Filter
      .Where(t => t.Plan.StorageStats.UploadUsed < t.Plan.StorageStats.UploadAvailable)

These look the same, but the new one does not work and I receive this error message:

Additional information: Unsupported filter: ({plan.sstats.used} < {plan.sstats.available}).

The back-end version is currently the same, so I don't see any reason why this shouldn't continue to be able to work.

How do I fix this? Is there a better way of doing this, whilst maintaining atomicity?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Seems MongoDb drive doesn't support it any more. Me personally see two possible solutions:

1) You query bson, not your objects, that should work (i have tried with my sample data out):

FilterDefinition<BsonDocument> filter = 
    new BsonDocument("$where", "this.plan.sstats.used<this.plan.sstats.available");

Waht is bad on this approach: your should query your collection as BsonDocument collection.

2) You query your collection as ToEnumerable() and than just add your filter as Where linq statement. That will work too, but you loose querying data directly on mongodb.

3) You could use aggregation framework, i did it this way:

var result = collection.Aggregate()
        .Group(r => r.Plan.StorageStats.UploadUsed - r.Plan.StorageStats.UploadAvailable,
              r => new {r.Key, Plans= r.Select(t=>t.Plan)} )
        .Match(r=>r.Key < 0)
        .ToEnumerable()
        .SelectMany(r=>r.Plans);

Negative on aggregate is that you couldn't combine it with your other Filters you use in Find() call.

over 4 years ago · Santiago Trujillo Relatório

0

So, I'd also asked over on Mongo's JIRA and was given this as a potential alternative. I'm posting it here in case anyone is dissatisfied with Maksim's answer.


It's possible to create just a filter definition:

FilterDefinition<C> filter = new JsonFilterDefinition<C>("{ $where : \"this.plan.sstats.used < this.plan.sstats.available\" }");

Since strings can be converted to FilterDefinitions you could also write either of the following which both end up creating a JsonFilterDefinition: var filter = (FilterDefinition<C>)"{ $where : \"this.plan.sstats.used < this.plan.sstats.available\" }";

// or using an implicit conversion

FilterDefinition<C> filter = "{ $where : \"this.plan.sstats.used < this.plan.sstats.available\" }";
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