Similar to the “Log” in SQL, is there a similar command to print operations for MongoDB?
context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
Similar to the “Log” in SQL, is there a similar command to print operations for MongoDB?
context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
Hi @Nicholas_Vella,
Welcome to the MongoDB Community Forums. In order to print the DB operations in the log (like the MQL), you can use LogTo
with any logger such as Console.WriteLine
and EnableSentitiveDataLogging
to make sure you can see all fields in the database while creating your DbContext.
public static MflixDbContext Create(IMongoDatabase database) =>
new(new DbContextOptionsBuilder<MflixDbContext>()
.UseMongoDB(database.Client, database.DatabaseNamespace.DatabaseName)
.EnableSensitiveDataLogging()
.LogTo(Console.WriteLine)
.Options);
Hope that helps.
Thanks,
Rishit.
Thank you, I was able to get the information I needed.
Topic | Replies | Views | Activity |
---|---|---|---|
Optimize JSON Output in MongoDB ToJson | 4 | 485 | May 2024 |
Casting IMongoQueryable<T> to IMongoQuerable<TInterface> | 0 | 248 | Jul 2024 |
cCreation of a database using python and nodejs | 0 | 22 | Aug 2024 |
Use maxTimeMs in bulk operations | 1 | 28 | Mar 11 |
Using DbPooling ignoresAutoTransactionBehavior flag | 7 | 50 | Mar 14 |