scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

Option to exclude. #38

Open michaeljota opened 8 years ago

michaeljota commented 8 years ago

Right now you can use populate to get just the fields you want, but, can you just exclude fields?

I mean something like this:

Person.loadOne({name: 'Billy'}, {populate: [-'address', -'spouse']});

or

Person.loadOne({name: 'Billy'}, {populate: ['-address', '-spouse']});

or maybe

Person.loadOne({name: 'Billy'}, {exclude: ['address', 'spouse']});

The expect behavior it's to exclude those fields in the loaded person. Of course right now you can just populate all the fields that you want, but if you add something else, you have to add it in populate too.

It's not a breaking feature, but it's a nice one to have I think.

Also, I see some issues about this. What if some one makes a request as:

Person.loadOne({name: 'Billy'}, {populate: ['address', '-spouse']});

Well, if you want to populate 'address' only, the '-spouse' will be exclude by default, that's the actual behavior.

michaeljota commented 8 years ago

Well, in the mean time, after loading the document(s). just delete the property to be exclude.

            delete user.hashedPassword;
            delete user.salt;
michaeljota commented 8 years ago

I'll try to find a way to do inside the BaseDocument, but trully not sure how to use it.

scottwrobinson commented 8 years ago

Hi Michael,

Yup, BaseDocument is the place to go for this, although changes to Document may be required as well. I'll look in to it.

Thanks!