c# - Building indexes in MongoDB with .NET driver 2.0 -
c# - Building indexes in MongoDB with .NET driver 2.0 -
what's new way build indexes new driver 2.0? there's no documentation whatsoever this.
apparently works new indexkeysdefinitionbuilder<>
interface that's got far.
you need phone call , await
createoneasync
indexkeysdefinition
using builders.indexkeys
:
static async task createindex() { var client = new mongoclient(); var database = client.getdatabase("db"); var collection = database.getcollection<hamster>("collection"); await collection.indexes.createoneasync(builders<hamster>.indexkeys.ascending(_ => _.name)); }
if don't have hamster
can create index in non-strongly-typed way specifying index's json representation:
await collection.indexes.createoneasync("{ name: 1 }");
c# .net mongodb mongodb-csharp mongodb-csharp-2.0
Comments
Post a Comment