Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const userSchema = new Schema({
- name: String,
- email: {type: String, unique: true},
- password: String,
- verified: Boolean,
- profile: {
- avatar: String,
- name: String,
- lai: String,
- actions: Number,
- points: Number
- }
- }
- const User = require('../models/user');
- const mongoose = require('mongoose');
- function updateUsers(){
- let array = {};
- User.find({}, function(err, users) {
- users.forEach(function(user) {
- let updated = {
- "avatar" :
- "",
- "name" : user.name,
- "lai" : "",
- "actions" : 0,
- "points" : 0
- };
- array[user._id] = updated;
- });
- userUpdate(array);
- });
- }
- function userUpdate(array){
- console.log(array);
- for (i in array){
- console.log("id is: " + i);
- console.log(array[i]);
- User.update({_id: i}, {$set: {profile: array[i]}});
- console.log("after call");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement