Rev 8 |
Blame |
Compare with Previous |
Last modification |
View Log
| Download
| RSS feed
using System;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
namespace Race
{
class MainClass
{
public static void Main
(string[] args
)
{
BsonClassMap
.RegisterClassMap<Participant
>
(
cm
=>
{
cm
.AutoMap();
cm
.GetMemberMap(c
=> c
.Email).SetIgnoreIfNull(true);
}
);
// 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 participant
= new Participant
("Jean-Claude",
"Duss",
1952);
collection
.Insert(participant
);
}
}
}