/node_modules/mongoose/lib/plugins/idGetter.js

https://bitbucket.org/coleman333/smartsite · JavaScript · 26 lines · 14 code · 5 blank · 7 comment · 4 complexity · b3fa2a55209076a62743e6afdca9a4e4 MD5 · raw file

  1. 'use strict';
  2. /*!
  3. * ignore
  4. */
  5. module.exports = function(schema) {
  6. // ensure the documents receive an id getter unless disabled
  7. var autoIdGetter = !schema.paths['id'] &&
  8. (!schema.options.noVirtualId && schema.options.id);
  9. if (autoIdGetter) {
  10. schema.virtual('id').get(idGetter);
  11. }
  12. };
  13. /*!
  14. * Returns this documents _id cast to a string.
  15. */
  16. function idGetter() {
  17. if (this._id != null) {
  18. return String(this._id);
  19. }
  20. return null;
  21. }