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

243
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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