Skip to content
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

Filter fields on document find #74

Open
boxic opened this issue Dec 2, 2022 · 1 comment
Open

Filter fields on document find #74

boxic opened this issue Dec 2, 2022 · 1 comment
Labels
enhancement v3 Planned for the v3 version

Comments

@boxic
Copy link

boxic commented Dec 2, 2022

✒️ Description

Basically, I would want to find a document, or many documents that meet the requirements of a filter. BUT not send back all the bulky data that may be contained inside of that document. Sort of like a distinct query, but to only include certain whitelisted fields, or include everything but certain blacklisted fields.

luckily there are already database commands that do that for us!

🤔 Why?

Here's what I currently have to do for this, it's a bit more tedious, since you have to craft your own string, then split the documents yourself

#
# Output doc:
#_command-results::1 : {
#    cursor : {
#        firstBatch : [
#            {doc1},
#            {doc2},
#            {etc}
#        ]
#    },
#    ok : "1.0",
#    $clusterTime : some timestamp bullshit,
#    operationTime : int timestamp
#}
#
# ref: https://www.mongodb.com/docs/manual/reference/command/find/#output
set {_command-results::*} to results of mongo command "{""find"": ""my-collection"",""filter"": { ""player"": ""%{_uuid}%"" },""projection"": { ""_id"": 0, ""very-large-file-to-exclude"": 0, ""field-2-to-exclude"": 0 },}" of database {mongo-database}
        
# Convert the nested results into their own documents
loop {_command-results::*}:
    set {_docs::*} to mongo embedded array with path "cursor.firstBatch" of loop-value```
@boxic
Copy link
Author

boxic commented Dec 2, 2022

edited cause apparently I don't know how to markdown in github lmao
it would be awesome if we could just say excluding fields "field-1", "field-2" and "field-3" to blacklist fields - or alternatively including only "field-4" and "field-5" to do a whitelist instead

@Romitou Romitou added the v3 Planned for the v3 version label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement v3 Planned for the v3 version
Projects
None yet
Development

No branches or pull requests

2 participants