foxhound87 / rfx-stack

RFX Stack - Universal App

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Use of UUID in Models/Services

pdfowler opened this issue · comments

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:

  • Remove _id from the list of hooks.remove in the SERVICE/hooks.after.js file
  • Add toJSON: { virtuals: true }, in the SERVICE/model.js Schema Definition

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.

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.