my Meanjs app is supposed to upload a logo into a nested schema, within my UserSchema. I am able to successfully upload the file, as I am able to store a profile photo for the user successfully. But when I am trying to save an image into the nested Schema, it fails.
My model looks something like this:
ClubSchema = {name:String,
logo:Buffer};
UserSchema = {name:String,
photo:Buffer,
club:[ClubSchema]
}
I am able to successfully insert all the data into my ClubSchema, but not the logo.
My client.controller.js
var user = new Users($scope.user);
console.dir(user.club); //I can see the logo here
for(var i = 0;i<user.club.length;i++){
user.club[i].logo = $scope.uploadedLogos[i]; //Still trying to force it into the object
user.club[i].hasLogo = true; //Mysterious hasLogo = false appears
}
user.$update(function(response) {
$scope.success = true;
console.log('Inside scope success User is ');
console.dir(user); //hasLogo=false appears in this and no logo
$location.path('/');
}, function(response) {
$scope.error = response.data.message;
});
My server.controller.js
if (user) {
// Merge existing user
user = _.extend(user, req.body);
user.updated = Date.now();
user.displayName = user.name;
user.save(function(err) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {
req.login(user, function(err) {
if (err) {
res.status(400).send(err);
} else {
res.json(user);
}
});
}
});
} else {
res.status(400).send({
message: 'User is not signed in'
});
}
The hasLogo field is completely baffling because no such assignment exists in my code. I added the hasLogo = true, hoping that somehow it would set the hasLogo to true and upload the image then, but that doesn't work either. I have no idea where this hasLogo is coming from. After the hasLogo = true loop, if I print the object, I can see two hasLogo fields, one true and the other false. After the $update success, it is always false. My model does not contain a hasLogo field.