[CSHARP-2381] How to create unique index using IMongoIndexManager.CreateOne with CreateIndexModel Created: 09/Sep/18 Updated: 27/Oct/23 Resolved: 03/Jan/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Command Operations |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Matteo Contrini | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
I'm not sure when this has changed, but since the
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.
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. |
| Comments |
| Comment by Aniket Manglam [ 08/Oct/20 ] | ||||||
|
As per the documentation, the CreateIndexOptions.ExpireAfter Property Gets or sets when documents expire (used with TTL indexes). Can anybody confirm that the new CreateOneIndexOptions.MaxTime property has the same purpose and can be seamlessly used with TTL indexes as it is not specifically mentioned in the documentation anywhere.
| ||||||
| Comment by Robert Stam [ 09/Jan/19 ] | ||||||
|
Thank you for pointing out that the documentation needs to be updated. I've created a ticket for that. See: | ||||||
| Comment by Matteo Contrini [ 09/Jan/19 ] | ||||||
|
Thanks, that works fine What about updating the documentation? It's still suggesting to use deprecated method overloads. | ||||||
| Comment by Robert Stam [ 03/Jan/19 ] | ||||||
|
When CreateMany was added some options needed to move into the model. CreateOne was changed to use model also for consistency with CreateMany. The way to create a unique index using the new methods is:
|