The following is my schemas for the document named 'Folder':
var permissionSchema = new Schema({
role: { type: String },
create_folders: { type: Boolean },
create_contents: { type: Boolean }
});
var folderSchema = new Schema({
name: { type: string },
permissions: [ permissionSchema ]
});
In my CMS there's a panel where I have listed all the folders and their permissions. The admin has access to edit single permission and save it.
But I don't want to save all the document so for that I implemented the following code:
savePermission: function (folderId, permission, callback) {
Folder.findOne({ _id: folderId }, function (err, data) {
var perm = _.findWhere(data.permissions, { _id: permission._id });
_.extend(perm, permission);
data.markModified("permissions");
data.save(callback);
});
}
But the problem is that my 'perm' variable is always unclear. I just want to know how to get the subdocument of a fetched document?