static void FilterUsinEQWithFilterDifinitionBuilder() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = new FilterDefinitionBuilder <BsonDocument>().Eq("undergrad", false); collection.Find(filter).ForEachAsync(doc => Console.WriteLine(doc)); }
static void FilterUsinEQWithBsonDocument() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = new BsonDocument("undergrad", new BsonDocument("$eq", false)); collection.Find(filter).ForEachAsync(doc => Console.WriteLine(doc)); }
static void FilterUsinEQWithString() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = "{undergrad: {'$eq': false}}"; collection.Find(filter).ForEachAsync(doc => Console.WriteLine(doc)); }
static void FilterWithString() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = "{Name: 'Keanu Reeves'}"; collection.Find(filter).ForEachAsync(doc => Console.WriteLine(doc)); }
static void FilterWithBsonDocument() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = new BsonDocument("Name", "Keanu Reeves"); collection.Find(filter).ForEachAsync(doc => Console.WriteLine(doc)); }
static void FilterByIdWithString() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = "{_id: ObjectId('5ea37c1edc6da61880bff131')}"; var doc = collection.Find(filter).FirstOrDefault(); Console.WriteLine(doc); }
static void FilterByIdWithBsonDocument() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); var filter = new BsonDocument("_id", new ObjectId("5ea37c1edc6da61880bff131")); var doc = collection.Find(filter).FirstOrDefault(); Console.WriteLine(doc); }
static void FilterUsinEQWithLambdaExpression() { var collection = new MongoDb <Student>().GetCollection("student"); collection.Find(x => x.Undergrad == false).ForEachAsync(doc => Console.WriteLine($"{doc.Id} - {doc.Name}")); }
static void UseOfFind() { var collection = new MongoDb <BsonDocument>().GetCollection("student"); collection.Find(FilterDefinition <BsonDocument> .Empty).ForEachAsync(doc => Console.WriteLine(doc)); }