Closed pdfowler closed 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.
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.
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), haveuuid
defined in the model, and in the service config haveid: uuid
.What's the main reason for this and not using the builtin Mongo
_id
property, or Mongooseid
virtual?Enabling the use of
id
(or_id
) in the client side would require the following changes:_id
from the list ofhooks.remove
in theSERVICE/hooks.after.js
filetoJSON: { virtuals: true },
in theSERVICE/model.js
Schema Definition