-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-4141: Clustered Indexes for all Collections. #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| { "key", options.ClusteredIndex.Key.Render(documentSerializer, serializerRegistry) }, | ||
| { "unique", options.ClusteredIndex.Unique }, | ||
| { "name", options.ClusteredIndex.Name, options.ClusteredIndex.Name != null } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ClusteredIndex is being "rendered" at the wrong level here. I suggest:
var clusteredIndex = options.ClusteredIndex?.Render(documentSerializer, serializerRegistry);
This is similar to how the Validator is rendered just below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And adding a Render method to ClusteredIndexOptions:
internal BsonDocument Render(IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry)
{
return new BsonDocument
{
{ "key", _key.Render(documentSerializer, serializerRegistry) },
{ "unique", _unique },
{ "name", _name, _name != null }
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: lots of our Render methods are public. Perhaps this one should be also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Moved. It's a grab bag whether our Render methods are internal or public. I'll stick with internal for now.
|
I think adding The non-generic |
rstam
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The API to create a clustered index is:
The
Keymust be{ _id: 1 }andUniquemust betrueat the moment, but the spec was written in such a way that the server can remove these requirements in the future and not require additional work by drivers. If you create anew ClusteredIndexOptions<T>(), these options will be defaulted automatically.Ideally I wanted to support non-generic
CreateCollectionsOptions.ClusteredIndex, butCreateCollectionOptions<TDocument>derives fromCreateCollectionOptions. I couldn't think of a way to define aCreateIndexOptions.ClusteredIndexproperty with typeClusteredIndexOptions<BsonDocument>but then change the type of the property on the derived type toCreateCollectionOptions<TDocument>.ClusteredIndextoClusteredIndexOptions<TDocument>. I opted to only support theClusteredIndexproperty onCreateCollectionOptions<TDocument>. If anyone has ideas, I'm all ears.