Skip to content

Instantly share code, notes, and snippets.

@jlesech
Created March 15, 2014 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlesech/9567326 to your computer and use it in GitHub Desktop.
Save jlesech/9567326 to your computer and use it in GitHub Desktop.
Mono-Mongo/Default serialization
using System;
using MongoDB.Driver;
namespace Race
{
class MainClass
{
public static void Main (string[] args)
{
// Get a Reference to the Client Object.
string connectionString = "mongodb://localhost";
MongoClient client = new MongoClient(connectionString);
// Get a Reference to a Server Object.
MongoServer server = client.GetServer();
// Get a Reference to a Database Object.
MongoDatabase database = server.GetDatabase("Race");
// Get a Reference to a Collection Object.
MongoCollection collection = database.GetCollection<Participant>("Participants");
// Insert a Document.
Participant participant1 = new Participant("Jean-Claude", "Duss", 62);
collection.Insert(participant1);
Participant participant2 = new Participant("Thierry", "La France");
collection.Insert(participant2);
}
}
}
using System;
namespace Race
{
public class Participant
{
#region Fields
private string firstName = string.Empty;
private string lastName = string.Empty;
private Nullable<byte> age = null;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Race.Participant"/> class.
/// </summary>
/// <param name='firstName'>
/// First name.
/// </param>
/// <param name='lastName'>
/// Last name.
/// </param>
public Participant(string firstName, string lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
/// <summary>
/// Initializes a new instance of the <see cref="Race.Participant"/> class.
/// </summary>
/// <param name='firstName'>
/// First name.
/// </param>
/// <param name='lastName'>
/// Last name.
/// </param>
/// <param name='age'>
/// Age.
/// </param>
public Participant(string firstName, string lastName, Byte age)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the first name.
/// </summary>
/// <value>
/// The first name.
/// </value>
public string FirstName
{
get { return this.firstName; }
set { this.firstName = value; }
}
/// <summary>
/// Gets or sets the last name.
/// </summary>
/// <value>
/// The last name.
/// </value>
public string LastName
{
get { return this.lastName; }
set { this.lastName = value; }
}
/// <summary>
/// Gets or sets the age.
/// </summary>
/// <value>
/// The age.
/// </value>
public Nullable<byte> Age
{
get { return this.age; }
set { this.age = value; }
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment