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

242
Vistas
Is there a way to call a user-defined function in mongo from C# code?

I have added the following function in my Mongo database:

db.system.js.save({
    _id: "testFunction",
    value: function (int) {
           
    return int;
    }
})

I'm using the following packages in my C# project:

mongocsharpdriver 2.14.1 MongoDB.Driver 2.14.1

The function runs with no issue in a Mongo shell.

Is there a way to run it in a C# code? I have searched for a solution for a few hours but with no luck.

Please note that the Eval method/option is not available in above driver version, so please don't suggest it.

In addition, I'm aware of the CommandDocument class but couldn't figure out how to create it for calling the above function.

Thanks in advance !

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I am also looking for the same but didn't find anything relevant so i decided to go with aggrgate() function in c# and suggesting to you also if you are not performing much complex queries in MongoDB function. The aggregate functions can also accept json format as MongoDB queries so you can try that something like this.

       database.GetCollection<BsonDocument>("collection").Aggregate()
          .Lookup("ForeignCollection", "LocalName", "ForeignName", "Object").Match("AnyFilter").Project(Builders<BsonDocument>.Projection.Exclude("field1").Include("field2")).ToList();
about 4 years ago · Juan Pablo Isaza 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