isDefaultIdIndex.js 444 B

123456789101112131415161718
  1. 'use strict';
  2. const get = require('../get');
  3. module.exports = function isDefaultIdIndex(index) {
  4. if (Array.isArray(index)) {
  5. // Mongoose syntax
  6. const keys = Object.keys(index[0]);
  7. return keys.length === 1 && keys[0] === '_id' && index[0]._id !== 'hashed';
  8. }
  9. if (typeof index !== 'object') {
  10. return false;
  11. }
  12. const key = get(index, 'key', {});
  13. return Object.keys(key).length === 1 && key.hasOwnProperty('_id');
  14. };