Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. const userSchema = new Schema({
  2. name: String,
  3. email: {type: String, unique: true},
  4. password: String,
  5. verified: Boolean,
  6. profile: {
  7. avatar: String,
  8. name: String,
  9. lai: String,
  10. actions: Number,
  11. points: Number
  12. }
  13. }
  14.  
  15. const User = require('../models/user');
  16. const mongoose = require('mongoose');
  17.  
  18. function updateUsers(){
  19. let array = {};
  20. User.find({}, function(err, users) {
  21. users.forEach(function(user) {
  22. let updated = {
  23. "avatar" :
  24. "",
  25. "name" : user.name,
  26. "lai" : "",
  27. "actions" : 0,
  28. "points" : 0
  29. };
  30.  
  31. array[user._id] = updated;
  32. });
  33.  
  34. userUpdate(array);
  35. });
  36. }
  37.  
  38. function userUpdate(array){
  39. console.log(array);
  40. for (i in array){
  41. console.log("id is: " + i);
  42. console.log(array[i]);
  43. User.update({_id: i}, {$set: {profile: array[i]}});
  44. console.log("after call");
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement