Query Untyped Object Inside a MongoDB
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.
CODE:
var db = server.GetDatabase(bsDatabase.Current as string);var collection = db.GetCollection(bsCollections.CurrencyManager.Current as string);
var allLevel = collection.Distinct("level");
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-731253/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Inside the C++ Object ModelIDEC++Object
- [Angular 2] Using a Reducer to Change an Object's Property Inside an ArrayAngularObjectIDE
- MongoDB的常用Query操作及操作符MongoDB
- [Javascript] Access private variable inside IIFE and mutate this through Object.prototype getter functionJavaScriptIDEObjectFunction
- Full postback triggered by LinkButton inside GridView inside UpdatePanelIDEView
- phpmysqlimysqli_query()mysqli_real_query()PHPMySql
- GCD Inside: GCD 宏GCIDE
- Query sqlSQL
- Query DSL
- reg query /?
- error:declared inside parameter listErrorIDE
- It was discovered inside the cheap lancel handbagsIDE
- typedef and struct inside class definition?StructIDE
- mysql 配置 General Query Log和# Slow Query LogMySql
- Uncaught TypeError: Object [object Object] has no method 'xxx'ErrorObject
- MySQL Query CacheMySql
- Parallel query & viewsParallelView
- Export Parameter : QueryExport
- coca SLOW QUERY
- 《Inside UE4》開篇IDE
- [Inside HotSpot] Java分代堆IDEHotSpotJava
- Mach-O Inside: BSS SectionMacIDE
- 《Inside UE4》目錄IDE
- Unable to preventDefault inside passive event listenerIDE
- inside sqlplus prelim(轉)IDESQL
- Inside Scoop of J2EEIDEOOP
- ES 筆記十:Query String & Simple Query String筆記
- flashback version query和 flashback transaction query簡單應用
- ObjectObject
- react-query手把手教程①-入門react-queryReact
- 介面返回[object,Object]解決方法Object
- Effective Object C 2.0 『熟悉Object C』Object
- Inside Java Newscast #1 深度解讀IDEJavaAST
- WebKit Inside: DOM樹的構建WebKitIDE
- GCD Inside: GCD 資料結構GCIDE資料結構
- 《Inside UE4》基礎概念IDE
- Cost Control: Inside the Oracle OptimizerIDEOracle
- Elasticsearch——query stringElasticsearch