foxhound87 / rfx-stack

RFX Stack - Universal App
MIT License
419 stars 42 forks source link

[Question] Use of UUID in Models/Services #43

Closed pdfowler closed 7 years ago

pdfowler commented 7 years ago

I've been using Mongo/Mongoose for a few years in a MEAN stack app and am trying to figure out some implementation details here. I noticed that the default services (user and post) all generate a UUID (using the setUUID hook), have uuid defined in the model, and in the service config have id: uuid.

What's the main reason for this and not using the builtin Mongo _id property, or Mongoose id virtual?

Enabling the use of id (or _id) in the client side would require the following changes:

foxhound87 commented 7 years ago

I suppose you use virtuals to define relations for your schema. The main reason is to abstract them inside feathers hooks instead, as feathers is multi-db compatible, the uuid can be used by different dbs and it's a standard. Just change models and adapter.

pdfowler commented 7 years ago

That makes sense. I'm slowly coming around to the whole feathers/mobx view of the world. In my past projects, I utilized Mongoose models heavily with virtual properties and static methods. I'm adjusting my thinking now to utilize after hooks to implement virtual properties there - which will allow me to remain database agnostic.

I'm still not 100% sold on UUIDs, but I understand why they're being used.