Hello I'd like to know if it's possible to create pseudo properties on Mondodb. This is, currently I have a collections users like this:
{_id: (_1), name: "user1", secret: "1"}
{_id: (_2), name: "user2", secret: "2"}
When I query the database. I do something like:
function getuser(objectId) {
db.users.find({_id : objectId}).toArray(function(err, result) {
x = result[0];
x.pseudoField1 = hash(secret);
return x;
});
}
Then I do some operations on the x
object, and return to put on the database, but before I have to filter the not needed properties, so I do:
y = {}
y._id = x._id
y.name = x.name
y.secret = x.secret
db.users.update({_id: y._id}, y);
What I'd like to do is know if there is any way to make the databse automaticaly return an object with the pseudoField1
with the function I want, and furthermore, when I issue an update with x
, only the fields _id
, name
and secret
get updated.