isExclusive.js 635 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const isDefiningProjection = require('./isDefiningProjection');
  3. /*!
  4. * ignore
  5. */
  6. module.exports = function isExclusive(projection) {
  7. const keys = Object.keys(projection);
  8. let ki = keys.length;
  9. let exclude = null;
  10. if (ki === 1 && keys[0] === '_id') {
  11. exclude = !!projection[keys[ki]];
  12. } else {
  13. while (ki--) {
  14. // Does this projection explicitly define inclusion/exclusion?
  15. // Explicitly avoid `$meta` and `$slice`
  16. if (keys[ki] !== '_id' && isDefiningProjection(projection[keys[ki]])) {
  17. exclude = !projection[keys[ki]];
  18. break;
  19. }
  20. }
  21. }
  22. return exclude;
  23. };