Mongoose indexing check if works

PHOTO EMBED

Fri May 21 2021 16:36:01 GMT+0000 (Coordinated Universal Time)

Saved by @shihor #mongoose #schema #indexing #checkifworks

// To check which fields are indexed
Product.collection
  .getIndexes({ full: true })
  .then((indexes) => {
    console.log('indexes:', indexes);
  })
  .catch(console.error);

// To check if indexing works
(async () => {
  const result = await Product.find(
    { friendlyName: 'Nice other Name' },
    '_id'
  ).explain('executionStats');
  console.log(result);
})();
content_copyCOPY

Check if indexing exists and if works