PopulateOptions.js 802 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const clone = require('../helpers/clone');
  3. class PopulateOptions {
  4. constructor(obj) {
  5. this._docs = {};
  6. if (obj == null) {
  7. return;
  8. }
  9. obj = clone(obj);
  10. Object.assign(this, obj);
  11. if (typeof obj.subPopulate === 'object') {
  12. this.populate = obj.subPopulate;
  13. }
  14. if (obj.perDocumentLimit != null && obj.limit != null) {
  15. throw new Error('Can not use `limit` and `perDocumentLimit` at the same time. Path: `' + obj.path + '`.');
  16. }
  17. }
  18. }
  19. /**
  20. * The connection used to look up models by name. If not specified, Mongoose
  21. * will default to using the connection associated with the model in
  22. * `PopulateOptions#model`.
  23. *
  24. * @memberOf PopulateOptions
  25. * @property {Connection} connection
  26. * @api public
  27. */
  28. module.exports = PopulateOptions;