You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a great idea. I love the "cleanness" of it. However, it lacks a feature which I need.
With the use of mongoosejs, I can override the _id type stored in the database. The reason I do this is to support UUID's as the key and not to have the disk storage overhead (almost %50) of a string.
I basically do the following:
set id as false in the schema, to prevent the system from generating one.
set the schema _id to use a mongoose type of UUID by importing the mongoose-uuid2 library, along with setting the default (auto-generate) by using a uuid.v4 by importing the library 'node-uuid' to give it a 'sql - identity - like' feel as records are inserted into the database.
then I use a virtual of id to get the value out of the database.
To prevent the hidden _ values from showing up on out put, I transform the output on a toJSON and toObject methods
The type is a binary bson type 4. To retrieve this value using a mongoose find I convert the uuid string to a the binary bson type 4 then do the comparison. I created a static method for this.
As you can imagine this complicates the schema and model to make it hard to read, plus things like ES6 inheritance are next to impossible
Hey @thxmike sorry I haven't responded yet. Unfortunately I don't have the time to work on this project at the moment. If you (or anyone you know) would be interested in coming on and helping to maintain it I'd love to have the help. Just let me know. Thanks!
This is a great idea. I love the "cleanness" of it. However, it lacks a feature which I need.
With the use of mongoosejs, I can override the _id type stored in the database. The reason I do this is to support UUID's as the key and not to have the disk storage overhead (almost %50) of a string.
I basically do the following:
As you can imagine this complicates the schema and model to make it hard to read, plus things like ES6 inheritance are next to impossible
Here is an example
The text was updated successfully, but these errors were encountered: