Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2381

How to create unique index using IMongoIndexManager.CreateOne with CreateIndexModel

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Command Operations

      I'm not sure when this has changed, but since the

      IMongoIndexManager.CreateOne(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken))

      overload has been marked as deprecated, I can't find a way to create a single unique index without using deprecated methods.

      In fact, the suggested one only accepts a CreateOneIndexOptions, which doesn't contain a property for setting the index as unique.

      IMongoIndexManager.CreateOne(CreateIndexModel<TDocument> model, CreateOneIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));

      Plus, I see no mention of this change in the package release notes, and the documentation still uses the methods that are marked as deprecated. This is very confusing.

      Is there a reason why those methods were marked as obsolete? It seems that avoiding those only creates problems, because of missing properties and a more complex input type (CreateIndexModel instead of IndexKeysDefinition, but the first just wraps the second).

      Thanks.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            matteocontrini Matteo Contrini
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: