20260619120000_create_libraryReferences_match_indexes.mjs 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. import Helpers from './lib/helpers.mjs'
  2. const tags = ['saas']
  3. // Partial indexes so docs without a given match token are not indexed. They
  4. // back the batch duplicate-detection query in findMatchingReferences.
  5. const newIndexes = [
  6. {
  7. key: { userId: 1, 'matchTokens.doi': 1 },
  8. name: 'userId_1_matchTokens.doi_1',
  9. partialFilterExpression: { 'matchTokens.doi': { $exists: true } },
  10. },
  11. {
  12. key: { userId: 1, 'matchTokens.authorTitleYear': 1 },
  13. name: 'userId_1_matchTokens.authorTitleYear_1',
  14. partialFilterExpression: {
  15. 'matchTokens.authorTitleYear': { $exists: true },
  16. },
  17. },
  18. ]
  19. const migrate = async client => {
  20. const { db } = client
  21. await Helpers.addIndexesToCollection(db.libraryReferences, newIndexes)
  22. }
  23. const rollback = async client => {
  24. const { db } = client
  25. await Helpers.dropIndexesFromCollection(db.libraryReferences, newIndexes)
  26. }
  27. export default {
  28. tags,
  29. migrate,
  30. rollback,
  31. }