-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Select entire document after using select: false #11474
Comments
If you use select false, then you basically say: hey I don't want to expose this attribute by a simple findOne or find by accident because of reasons like security. So why are you using select false? |
ditto ^ |
Thats totally the case, I'm using it to hide attributes that I won't use in the response! Lets say I'm not interested in send a list of created orders by users to my endpoint response, but I need to use the list for something else (comparison, searching, etc). To archieve that, I'll need to use Its not really a big deal, but I missed this option the week with a model I have. |
In this case you can drop the field with |
I would actually prefer to always select with an object and not with a string. Anyhow |
Nice! I don't want to cause trouble or make this a big deal, just wondering if there was a good option to do it without needing to add a string everywhere. I'll think about another object or a const string with a method to get all fields available. Thanks. |
Actually I also need this feature for selecting All fields for Admin side so instead of writing all select:false fields manually Is there any better way you found? |
No ): I ended up adding everything in a single string when I needed... |
a little unfortunate that mongoose does not have this. Every api surely has an admin side which needs to fetch all fields in the db. having to chain .select(insert 20 fields here) is just a pain |
…hema-level select: false Fix #11474
feat(query): add schemaLevelProjections option to query to disable schema-level select: false
Thanks guys for this feature <3 |
Do you want to request a feature or report a bug?
Question / feature
What is the current behavior?
Currently, if we use
select: false
in a schema, we need to doModel.findOne({ _id }).select("+field_a")
to get its value.What is the expected behavior?
We could have an option to select the entire document, ignoring the
select: false
, it would not require us to do something likeModel.findOne({ _id }).select("+field_b +field_c +field_d +field_e ... +field_n")
. I feel this is necessary for some situations, but I couldn't figure a proper way to achieve this. I couldn't find anywhere an answer to this and I did not get an answer in stack overflow. Any idea is welcome!What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node v16.14.0
mongoose v6.2.4
mongodb v5.0.6
The text was updated successfully, but these errors were encountered: