[CSHARP-1575] Better way to create indexes Created: 21/Feb/16  Updated: 24/Mar/16  Resolved: 24/Mar/16

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Zeioth Assignee: Unassigned
Resolution: Done Votes: 0
Labels: index, indexes
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Hi, I just upgraded from 1.9 to 2.2 and i think the new changes are great. Said this, I think there's room for improvement in the process of create indexes.

This is my wrapper of indexes.CreateOne(). As you can see, there's no general way to tell a to the method if an index key is ascending or descending.

So, what do you think about this kind of implementation?
As you can see, using something like keys.Add() method it's MUCH easier to set the directions of multiple keys, specially when you have many of them. Thank you for your time.



 Comments   
Comment by Zeioth [ 23/Feb/16 ]

Yes Craig thank you so much. This solution has significantly less bloat code. Then I think this issue is closed.

Comment by Craig Wilson [ 23/Feb/16 ]

Hi Zeioth,

This is what I think you are saying: The direction of the indexes is indicated by the method name and not a parameter.

I believe this is possible by using a BsonDocument and let that get automatically converted to an IndexKeyDefinition<TDocument>.

keys = Builders<TDocument>.IndexKeys.Combine(new BsonDocument("fieldName", 1), new BsonDocument("fieldName2", -1));

Does this satisfy your need?

Generated at Wed Feb 07 21:40:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.