Skip to content

Instantly share code, notes, and snippets.

var document = new BsonDocument { { "_id", 1 }, { "x", 2 } };
await collection.InsertOneAsync(document);
var filter = new BsonDocument("x", new BsonDocument("$gte", 100));
var documents = await collection.Find(filter).ToListAsync();
var filter = new BsonDocument("x", new BsonDocument("$gte", 100));
var documents = await collection.Find(filter).ToListAsync();
var filter = new BsonDocument("x", new BsonDocument("$gte", 100));
await collection.Find(filter).ForEachAsync(async document =>
{
await ProcessDocumentAsync(document);
});
var client = new MongoClient("mongodb://localhost");
var server = client.GetServer();
var database = server.GetDatabase("test"); // this database uses the legacy API
var client = new MongoClient("mongodb://localhost");
var database = client.GetDatabase("test"); // this database uses the new API
var client = new MongoClient("mongodb://localhost");
var database = client.GetDatabase("foo");
var collection = database.GetCollection<BsonDocument>("bar");
var document = new BsonDocument { { "_id", 1 }, { "x", 2 } };
await collection.InsertOneAsync(document);
shard01:PRIMARY> c = db.oplog.rs.find( { fromMigrate : { $exists : false } } ).addOption( DBQuery.Option.tailable ).addOption(DBQuery.Option.awaitData)
{ "ts" : Timestamp(1422998530, 1), "h" : NumberLong(0), "v" : 2, "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" } }
{ "ts" : Timestamp(1422998574, 1), "h" : NumberLong("-6781014703318499311"), "v" : 2, "op" : "i", "ns" : "test.mycollection", "o" : { "_id" : 1, "data" : "hello" } }
{ "ts" : Timestamp(1422998579, 1), "h" : NumberLong("-217362260421471244"), "v" : 2, "op" : "i", "ns" : "test.mycollection", "o" : { "_id" : 3, "data" : "hello" } }
{ "ts" : Timestamp(1422998584, 1), "h" : NumberLong("7215322058367374253"), "v" : 2, "op" : "i", "ns" : "test.mycollection", "o" : { "_id" : 5, "data" : "hello" } }
shard01:PRIMARY> c.hasNext()
true
shard01:PRIMARY> c.next()
{
"ts" : Timestamp(1423049506, 1),
meteor:PRIMARY> db.currentOp()
{
"inprog" : [
{
"opid" : 345,
"active" : true,
"secs_running" : 4,
"op" : "getmore",
"ns" : "local.oplog.rs",
"query" : {