set_rich_text_beta_users.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const fs = require('fs')
  2. const path = require('path')
  3. const mongojs = require('../../app/js/infrastructure/mongojs')
  4. const { db, ObjectId } = mongojs
  5. const async = require('async')
  6. console.log('Finding users for ids specified')
  7. const text = fs.readFileSync(path.join(__dirname, 'beta-users.txt'))
  8. const textByLine = text
  9. .toString()
  10. .split('\n')
  11. .map(function(stringId) {
  12. return ObjectId(stringId)
  13. })
  14. db.users.find({ _id: { $in: textByLine } }, function(err, users) {
  15. if (err) throw err
  16. if (users.length) {
  17. console.log('Found ' + users.length + ' users')
  18. async.each(
  19. users,
  20. function(user, callback) {
  21. console.log('setting betaProgram==true for: ' + user._id)
  22. db.users.update(
  23. {
  24. _id: user._id
  25. },
  26. {
  27. $set: {
  28. betaProgram: true
  29. }
  30. },
  31. callback
  32. )
  33. },
  34. function(result, err) {
  35. if (err) {
  36. console.log(err)
  37. }
  38. process.exit(0)
  39. }
  40. )
  41. } else {
  42. console.log('No users found matching those ids')
  43. process.exit(0)
  44. }
  45. })