Open vd3d opened 4 years ago
I don't have experience on that before. Can you explain more please? We havent't got any problem related to that. Why do you think we should change it?
Because you use the "C# legacy" UID format. Today there is a new "standard" one.
Also, if I want to create jobs in any language, it is preferrable to not have something related to .NET
Also, I suspect (to verify) that the keys range can be bigger with the standard one, ie. you can scale more.
Thanks for the information. I will investigate that. Anyone can do it today for their applications. We will decide to make it default on the startup template or in the framework.
Currently, all Guid
properties are stored as LUUID (Legacy UUID) in mongodb, which has problems with converting due to different byte orders being used.
More info can be found here:
https://mongodb.github.io/mongo-csharp-driver/2.11/reference/bson/guidserialization/background/
To use the latest standard, one must set the GuidRepresentation
to Standard
. However, it is stated here that BsonDefaults.GuidRepresentation
is obsolete:
https://mongodb.github.io/mongo-csharp-driver/2.11/apidocs/html/P_MongoDB_Bson_BsonDefaults_GuidRepresentation.htm
The new way of setting this is by using serializers. Currently i am able to set this in OnApplicationInitialization
of MongoDbModule
. Now all my Guid
s are of UUID type.
Here is my code;
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3;
BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard));
}
I would like to create a PR but, current dev branch is using .net5 which requires installing a separate VS preview version to use latest MSBuild. If that's okay, i can create a new branch from a previous branch which uses .net3.1.
Another note;
If you are using MongoDB with GuidRepresentationMode.V3 and configuring Guid
as ExtraProperty of an object (Object Extension), mongodb driver throws error;
"This constructor can only be used when BsonDefaults.GuidRepresentationMode is V2".
Example:
ObjectExtensionManager.Instance.Modules().ConfigureIdentity(identity => {
identity.ConfigureUser(user => {
user.AddOrUpdateProperty<System.Guid>("WarehouseId");
});
});
user.SetProperty("WarehouseId", id); //id is of type System.Guid
hi @mtozlu
We should change this option in the template project and not in the mongodb module. Otherwise it will be a breaking change.
Since this is configurable, maybe we shouldn't change it, because currently it does not affect our application.
"This constructor can only be used when BsonDefaults.GuidRepresentationMode is V2".
Can you provide an example project?
In 3.x releases of mongo driver, V3 will be the default with no ability to change.
In the v2.x versions of the driver V2 is the default mode but V3 mode is supported. In future v3.x versions of the driver V3 will be the default mode (and support for V2 mode will be removed).
In that case if abp mongo package is upgraded to use mongo 3.x driver, all applications using 2.x version will have a breaking change since all UUID's in their databases are of legacy type. Clearly, some upgrading strategy needs to be discussed before using 3.x packages in abp.
Since this is configurable, maybe we shouldn't change it, because currently it does not affect our application.
Current template applications do not have any problem but they use Legacy UUID type. Legacy UUID's have problems as described in previous comments. Maybe it can be changed in template application or in mongodb project using MongoClientSettings
(see #6036) which has a GuidRepresentation
property.
"This constructor can only be used when BsonDefaults.GuidRepresentationMode is V2".
Can you provide an example project?
Regarding this; it is about the scenario if anyone wants to use new GuidRepresentation with the way i described in this comment and after that, if they want to use System.Guid
type in an extended object (using abp object extending system) as described in this comment, the driver throws an error.
So it was just a note to consider if abp wants to use new GuidRepresentationMode.
Here is an example project, just run the DbMigrator
to observe the error.
The changes i made are specified in commits.
https://github.com/mtozlu/abp-example-guid-representation
In that case if abp mongo package is upgraded to use mongo 3.x driver, all applications using 2.x version will have a breaking change since all UUID's in their databases are of legacy type.
There is currently no 3.x package. right?
There is currently no 3.x package. right?
No. It is not released yet.
Any news?
Hi,
I suspect that you should use BsonDefaults.GuidRepresentation = GuidRepresentation.Standard !