20260424120000_back_fill_users_analyticsId.mjs 545 B

123456789101112131415161718192021222324
  1. import { db } from './lib/mongodb.mjs'
  2. import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
  3. const tags = ['saas', 'server-ce', 'server-pro']
  4. const migrate = async () => {
  5. await batchedUpdate(db.users, { analyticsId: { $exists: false } }, [
  6. { $set: { analyticsId: { $toString: '$_id' } } },
  7. ])
  8. }
  9. const rollback = async () => {
  10. await batchedUpdate(
  11. db.users,
  12. { $expr: { $eq: [{ $strLenCP: '$analyticsId' }, 24] } },
  13. { $unset: { analyticsId: 1 } }
  14. )
  15. }
  16. export default {
  17. tags,
  18. migrate,
  19. rollback,
  20. }