Skip to content

Instantly share code, notes, and snippets.

@joelmartinez
Created September 25, 2011 13:03
Show Gist options
  • Save joelmartinez/1240580 to your computer and use it in GitHub Desktop.
Save joelmartinez/1240580 to your computer and use it in GitHub Desktop.
Minimal C#/MongoDb HowTo
MongoServer server = MongoServer.Create("mongodb://TheUserName:ThePassword@The.Url.Com:12345/TheDatabaseId");
MongoDatabase mongo = server.GetDatabase("<TheDatabaseId>");
var employees = mongo.GetCollection<TheClass>("TheCollectionName");
var cursor = employees.FindAllAs<TheClass>();
var item = cursor.FirstOrDefault();
....
public class TheClass
{
[BsonId]
public object _id { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment