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

391
Vistas
Mongodb c# driver: view MQL bson query generated from linq

Using the latest version (2.14) is there any way to view the bson query document generated by a specific linq query?

I want to do this for two reasons:

  1. debugging queries
  2. copying them to run in another mongo client like compass

I know I can enable profiling, but I can't see any way to guarantee a query you find in the mongo log was generated by a specific line of code or query. Plus it's a bit long winded to do it via profiling.

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

0

You have 2 options to get MQL query from LINQ request:

  1. Install lately released query analyzer. As I know it may not be 100% accurate if you use global static serialization configuration.
  2. Configure CommandStartedEvent event subscriber and analyze Command document. Pay attention that you may need to remove some technical fields like $db (maybe few more) that might not be parsed by compass correctly, you will see it in the exception message if any.
over 4 years ago · Santiago Trujillo Denunciar

0

@dododo answer is the right and best one, I'm just adding some code here which works for option 2:

    var settings = MongoClientSettings.FromUrl(new MongoUrl(@"mongodb://localhost"));
    settings.ClusterConfigurator = builder =>
    {
        builder.Subscribe<CommandStartedEvent>(x =>
        {
            var queryDocument = x.Command;
        });
    };

    var client =  new MongoClient(settings);
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