« Mongodb and csharp » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
(→Filter) |
(→Filter) |
||
Ligne 14 : | Ligne 14 : | ||
filter &= builder.Eq(x => x.Property1, "id"); | filter &= builder.Eq(x => x.Property1, "id"); | ||
filter &= builder.In(x => x.Property1, new[] { "id1", "id2" }); // filter by Property1 equals to one of the ids | filter &= builder.In(x => x.Property1, new[] { "id1", "id2" }); // filter by Property1 equals to one of the ids | ||
var result = (await collection.FindAsync(filter)).ToList(); | |||
</kode> | </kode> |
Version du 15 mars 2024 à 16:22
Access to a collection
var mongoClient = new MongoClient("MONGODB_CONNECTION_STRING"); var database = mongoClient.GetDatabase("DB_NAME"); var collection = database.GetCollection<Collection>("COLLECTION_NAME"); |
Filter
var builder = Builders<MyClass>.Filter; FilterDefinition<MyClass> filter = filterDefinition.Empty; filter &= builder.Eq(x => x.Property1, "id"); filter &= builder.In(x => x.Property1, new[] { "id1", "id2" }); // filter by Property1 equals to one of the ids var result = (await collection.FindAsync(filter)).ToList(); |