有没有办法记录MongoDB C#驱动程序生成的实际查询并发送给mongodb?就像在SQL Server中一样,您拥有SQL Profiler,可以显示所有传入的查询。使用C#驱动程序分析MongoDB查询
13
A
回答
14
db.setProfilingLevel(2);
14
您可以启用分析,看看在MongoDB中记录的实际查询为@ pingw33n建议。
或者可以为collection.Find创建extention方法有日志数据:
public static class MongodbExtentions
{
public static MongoCursor<T> FindAsAndLogQuery<T>(this MongoCollection<T> coll,
IMongoQuery query)
{
var queryString = query.ToJson();
//log query here , insert into mongodb, etc ...
return coll.FindAs<T>(query);
}
}
0
扩展方法@Andrew建议将只在搜索内容中的查询工作。 从MongoDB 3.2开始,你可以做一些类似于下面的事情,它可以处理所有的查询。
private static void LogQuery<TEntity>(string queryType, FilterDefinition<TEntity> filter,
UpdateDefinition<TEntity> update, IMongoCollection<TEntity> collection)
where TEntity : class, new()
{
var renderedFilter = filter.Render(collection.DocumentSerializer, collection.Settings.SerializerRegistry);
var renderUpdate = update.Render(collection.DocumentSerializer, collection.Settings.SerializerRegistry);
// Log you shell scrip as string to a file or DB
Log.Debug(
$"use {collection.Database.DatabaseNamespace.DatabaseName} db.{collection.CollectionNamespace.CollectionName}.{queryType}({renderedFilter.ToJson()},{renderUpdate.ToJson()})");
}
相关问题
- 1. MongoDB查询C#驱动程序
- 2. Mongodb java驱动程序3.0查询
- 3. MongoDB C驱动程序
- 4. 如何使用MongoDb Scala驱动程序进行同步查询
- 5. 使用Java驱动程序运行准备好的MongoDB查询
- 6. 聚集查询MongoDB的Java驱动程序使用极限
- 7. MongoDB的:建立在C#中的驱动程序查询
- 8. MongoDB的C#驱动程序查询总是返回空
- 9. 如何杀死来自C#驱动程序的长查询 - mongodb
- 10. 部分使用c#驱动程序的mongodb upsert?
- 11. 如何使用MongoDB C#驱动程序进行$查找?
- 12. 驱动程序中缺少MongoDB驱动程序(查询生成器)?
- 13. MongoDB C#驱动程序,使用正则表达式查询数组元素
- 14. 使用MongoDB的C#驱动程序写入与正则表达式查询ElementMatch
- 15. 如何在使用C驱动程序时为MongoDB查询设置MaxTimeMS(mongoc)
- 16. 使用PHP驱动程序深入查询MongoDB子集两级深入使用PHP驱动程序
- 17. 使用MongoDB的C#驱动
- 18. 使用mongodb c#和C++驱动程序修改bson文档
- 19. MongoDB C#驱动程序投影$ elemMatch $
- 20. MongoDB的C++驱动程序安装
- 21. MongoDB的C#2.0驱动程序SetSerializationOptions
- 22. Mongodb C++驱动程序和GridFS支持
- 23. C#MongoDB驱动程序故障(NORM)
- 24. MongoDB:哪个C驱动程序?
- 25. 有GridFS的C#MongoDB驱动程序
- 26. 在C#中使用IBM Informix ODBC驱动程序查询问题
- 27. 通过PHP驱动程序的MongoDB查询返回没有resutls
- 28. Mongodb Nodejs驱动程序聚合查询不返回数据
- 29. MongoDB和Java驱动程序:查询中的“忽略大小写”
- 30. MongoDB的Java驱动程序:mongojack,通过子文档ID查询