Derik Whittaker

Syndication

News


Using LINQPad to query your Mongo Database

Recently I started playing around w/ Mongo for a side project and so far it has been a cake walk.  While learning how to use Mongo I quickly realized that the ‘out of the box’ tool to query the database was the command line.  Now this works great, but is limited.  I am not able to easily save and reuse any scripts.  While doing some simple research about different Admin Consoles for Mongo I noticed that I could use LINQPad to do accomplish my needs.

In order to use LINQPad there are a few steps which need to be performed, the first of which is to download and install LINQPad.  Once you have this installed we can get down to the nuts and bolts.

How to reference the Mongo C# Library:
When ever I need to reference any assemblies I want to use NuGet when at all possible, fortunately I am in luck because LINQPad has native support for this.

  1. Create a new LinqPad C# Expression Query
  2. Right click the query editor and choose Query Properties
  3. Click the ‘Add NuGet’ button in the Query Properties dialog
  4. Search for the MongoCSharpProvider, click Add To Query
  5. Notice that the ‘Add to Query’ link changes to ‘Add Namespaces’, click this.  A dialog will popup, select all the items (I am lazy and this is easier) click OK
  6. When you are taken back to the Query Properties window you should see the following
    image

Now that we have Mongo Client referenced we can create the code needed to make our connection and do something useful

Connecting to Mongo in LinqPad

To do this you can add code as seen below.

image

 

Once you have added the above code you can do anything you want to your Mongo db and save the scripts for later.

Till next time,


Posted 12-18-2013 1:48 PM by Derik Whittaker
Filed under:

[Advertisement]

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)