PopulateOptions.js 829 B

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