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

248
Vistas
MongoDB and LINQ: "NOT IN" clause

I have two collections, one is a list of image names, the second is a subset of that list. When a task has been completed its name is inserted into the second collection.

I need to retrieve a set of not yet completed image names from the first collection. I have achieved this successfully with:

var processedNames = processed.AsQueryable().Select(x => x.ImageName).ToArray();
foreach (var result in results.Where(x => !processedNames.Contains(x.ImageName))

However this brings a large list of strings back from the database and then sends it back to the database in a single document, which as well as being inefficient will break eventually.

So I tried to rewrite it so it's all performed server side with:

            var results = from x in captures
                          join complete in processed.AsQueryable() on x.ImageName equals complete.ImageName into completed
                          where !completed.Any()
                          select x;

This fails with:

System.NotSupportedException: '$project or $group does not support {document}.'

I also tried using the non LINQ API:

                var xs = capturesCollection.Aggregate()
                    .Lookup("Processed", "ImageName", "ImageName", @as: "CompletedCaptures")
                    .Match(x => x["CompletedCaptures"] == null)
                    .ToList();

This fails with:

MongoDB.Bson.BsonSerializationException: 'C# null values of type 'BsonValue' cannot be serialized using a serializer of type 'BsonValueSerializer'.'

How can I achieve this query completely server side with the C# driver? A pure LINQ solution is preferable for portability.

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

0

I worked out how to do it with the Aggregate API:

                var results = capturesCollection.Aggregate()
                    .As<CaptureWithCompletions>()
                    .Lookup(processed, x => x.ImageName, x => x.ImageName, @as:(CaptureWithCompletions x) => x.CompletedCaptures)
                    .Match(x => !x.CompletedCaptures.Any())
                    //.Limit(2)
                    .ToList();
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