首页 > Linux操作系统 > Linux操作系统 > Query Untyped Object Inside a MongoDB

Query Untyped Object Inside a MongoDB

原创 Linux操作系统 作者:jieforest 时间:2012-05-28 12:51:03 0 删除 编辑

I’ve blogged about using MongoDb to store log4net logs,

but the original appender has a littleproblem, it stores a BsonDocument inside the MongoCollection, and does not use any C# object andwhen it is time to query data you cannot use the new LINQ Mongo provider that is included in newest C# drivers (1.4), because data is completely untyped.

This is usually not a big problem, because you can querya collection using simple JSON-like query, but if you are used to standard LINQ provider, probably you will get alittle bit lost on how to create the JSON query to retrieve the data you need.

This is the scenario I need to solve:

I have a stupid Winform. that is able to show someinformation from a standard Log4Net Sql database (using the adonetappender) andI want to be able to use the very same interface to load data from mongodatabase.

First of all I need to load all distinct value for the property level and loggerName, because I have acombo where the user can filter for Severity (ERROR, WARN, INFO, Etc.) and alist of checkboxes used to filter for loggerName. Luckily enough, mongo offersuch a functionality out of the box.


var db = server.GetDatabase(bsDatabase.Current as string);
var collection = db.GetCollection(bsCollections.CurrencyManager.Current as string);
var allLevel = collection.Distinct("level");

来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

上一篇: A Hadoop Primer
请登录后发表评论 登录


  • 博文量
  • 访问量