Collections
Get a collection reference
IMongoDatabase.GetCollection<T>(string collection)// Get a reference to the database
var database = Client
.GetDatabase(Constants.SamplesDatabase);
// Get a reference to a database's collection named 'users'
var personsTypedCollection = database
.GetCollection<User>(Constants.UsersCollection);public class User
{
[BsonId]
[BsonIgnoreIfDefault] // required for replace documents
public ObjectId Id { get; set; }
public Gender Gender { get; set; }
public string FirstName {get; set; }
public string LastName {get; set; }
public string UserName {get; set; }
public string Avatar {get; set; }
public string Email {get; set; }
public DateTime DateOfBirth {get; set; }
public AddressCard Address {get; set; }
public string Phone {get; set; }
[BsonIgnoreIfDefault]
public string Website {get; set; }
public CompanyCard Company {get; set; }
public decimal Salary { get; set; }
public int MonthlyExpenses { get; set; }
public List<string> FavoriteSports { get; set; }
public string Profession { get; set; }
}var bsonPersonsCollection = database
.GetCollection<BsonDocument>(Constants.UsersCollection);Create collections
Capped collection
List collections
Drop collections
Last updated