handleSpreadDoc.js 380 B

1234567891011121314151617
  1. 'use strict';
  2. const utils = require('../../utils');
  3. /**
  4. * Using spread operator on a Mongoose document gives you a
  5. * POJO that has a tendency to cause infinite recursion. So
  6. * we use this function on `set()` to prevent that.
  7. */
  8. module.exports = function handleSpreadDoc(v) {
  9. if (utils.isPOJO(v) && v.$__ != null && v._doc != null) {
  10. return v._doc;
  11. }
  12. return v;
  13. };