[CSHARP-1309] IndexKeysDefinitionBuilder should support defining multikey indexes on members of an array of embedded documents Created: 11/Jun/15 Updated: 21/Jul/22 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | API |
| Affects Version/s: | 2.0 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Craig Wilson | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 10 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Description |
| Comments |
| Comment by Tyler Ohlsen [ 21/Aug/19 ] | |||||||||||||||||||||||
|
This is also uniquely a problem with dictionary items. We use the dictionary representation of `ArrayOfDocuments` and we need an index on the dictionary keys. Therefore, the index I want is: { "MyDictionary.k": 1 }, but there's currently no way to represent that in a type-safe way. Queries are able to build the correct breadcrumb property name (with 'k') by a type-safe expression, so I'm surprised that index definitions are not able to do the same. | |||||||||||||||||||||||
| Comment by Alexander Regueiro [ 25/Sep/17 ] | |||||||||||||||||||||||
|
Any progress on this lately? | |||||||||||||||||||||||
| Comment by Craig Wilson [ 08/Apr/16 ] | |||||||||||||||||||||||
|
It would certainly go onto the existing IndexKeysDefinitionBuilder<T> class and then also live as an extension method on the IndexKeysDefinition<T> class. You can see the existing implementations here: | |||||||||||||||||||||||
| Comment by Kenneth Siewers M?ller [ 08/Apr/16 ] | |||||||||||||||||||||||
|
Thanks! Well, I actually didn't spend a whole lot of time on the code, but I will definitely look into your proposal. | |||||||||||||||||||||||
| Comment by Craig Wilson [ 08/Apr/16 ] | |||||||||||||||||||||||
|
Hi Kenneth, Couple of things. First, submitting a pull request will let us get your name in the commit history, which is nice for you and a thanks for helping us out. Second, this looks like a good start, but isn't there yet. You're calling the Render method very early in the process, which means that you are having to us the global BsonSerializer.LookupSerializer method. This defeats the purpose of the XXXDefinition classes. What you are going to want to do create a class that inherits from IndexKeysDefinition<T> and return that from these methods. This class contains a Render method you'll override and be provided both with a serializer and a serializerRegistry to use. Overall, I think this looks like a good solution. Great job. | |||||||||||||||||||||||
| Comment by Kenneth Siewers M?ller [ 08/Apr/16 ] | |||||||||||||||||||||||
|
I have created two extension methods, which works on strongly typed collections:
Usage:
I know it's not working on nested arrays etc. but it does generate the proper indexes. There might also be a much easier way to create the property names, but I haven't found it. |