Closed s7dhansh closed 8 years ago
You do need to check in case someone set it to be excluded - it shouldn't be replaced in that case. Only setting it if it's not there should do it.
Ok. Makes sense.
I tested this with excluded fields and I got errors like this: MongoError: Can't canonicalize query: BadValue Projection cannot have a mix of inclusion and exclusion.
You should move it a couple lines down into the code that only runs if there's an included field already - then you wouldn't need the extra check either.
So what you encountered was probably because we can not mix inclusions and exclusions - http://stackoverflow.com/questions/24949544/mongodb-cant-canonicalize-query-badvalue-projection-cannot-have-a-mix-of-incl
I tried with _id: 0, and I get this error Error: You may not observe a cursor with {fields: {_id: 0}}
. So I guess we can not exclude _id at any cost in publications. Still I have improved the check.
Doing it in the inclusion block will require much more checks and code, so I assume this is the best way. What say?
Oh, I too encountered your error on pure exclusions, so mongo does not allow to mix _id: 1 with pure exclusions too. Will try to figure out a way.
@aslagle any feedback?
Looks good, thanks!
allow filtering on _id, when only selective fields are being published. There is no need to check for the existence of settings.fields._id IMO, because anyways we have to set it on.