var cursor = db.userimages.find();
while (cursor.hasNext()) {
  var x = cursor.next();
  print("Before: "+x['s3url']);
  x['s3url'] = x['s3url'].replace('s3.amazonaws.com/nibbl_filepicker/', 'd23kv44re9c2ys.cloudfront.net/');
  print("After: "+x['s3url']);
  db.userimages.update({_id : x._id}, x);
}

var cursor = db.userimagesnormalized.find();
while (cursor.hasNext()) {
  var x = cursor.next();
  print("Before: "+x['s3url']);
  x['s3url'] = x['s3url'].replace('s3.amazonaws.com/nibbl_filepicker/', 'd23kv44re9c2ys.cloudfront.net/');
  print("After: "+x['s3url']);
  db.userimagesnormalized.update({_id : x._id}, x);
}


var cursor = db.useravatarimg.find();
while (cursor.hasNext()) {
  var x = cursor.next();
  print("Before: "+x['s3url']);
  x['s3url'] = x['s3url'].replace('s3.amazonaws.com/nibbl_filepicker/', 'd23kv44re9c2ys.cloudfront.net/');
  print("After: "+x['s3url']);
  db.useravatarimg.update({_id : x._id}, x);
}


var cursor = db.useravatars.find();
while (cursor.hasNext()) {
  var x = cursor.next();
  print("Before: "+x['s3url']);
  x['s3url'] = x['s3url'].replace('s3.amazonaws.com/nibbl_filepicker/', 'd23kv44re9c2ys.cloudfront.net/');
  print("After: "+x['s3url']);
  db.useravatars.update({_id : x._id}, x);
}


var cursor = db.userdishes.find();
while (cursor.hasNext()) {
  var x = cursor.next();
  print("Before: "+x['s3url']);
  x['s3url'] = x['s3url'].replace('s3.amazonaws.com/nibbl_filepicker/', 'd23kv44re9c2ys.cloudfront.net/');
  print("After: "+x['s3url']);
  db.userdishes.update({_id : x._id}, x);
}



var cursor = db.userimages.find();
while (cursor.hasNext()) {
  var x = cursor.next();
  print("Before: "+x['s3url']);
  x['s3url'] = x['s3url'].replace('s3.amazonaws.com/nibbl_filepicker/', 'd23kv44re9c2ys.cloudfront.net/');
  print("After: "+x['s3url']);
  db.userimages.update({_id : x._id}, x);
}

db.person.find().forEach(
    function (elem) {
        db.person.update(
            {
                _id: elem._id
            },
            {
                $set: {
                    name: elem.firstname + ' ' + elem.lastname
                }
            }
        );
    }
);

db.users.find().forEach(
	function (elem) {
		db.userdata.update(
		{
			ownerId:elem._id
		},
		{
			$set: {
				displaynameurl:elem.username
			}
		}
		);
	}
);