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

Help using aggregate_raw_results #56

Open
martyzz1 opened this issue Feb 13, 2024 · 2 comments
Open

Help using aggregate_raw_results #56

martyzz1 opened this issue Feb 13, 2024 · 2 comments

Comments

@martyzz1
Copy link

martyzz1 commented Feb 13, 2024

I've been going around in circles a bit trying to understand if this library can be used to speed up decoding an aggregation query.

Or whether after recent pymongo updates its needed at all.

documents = []

cursor = collection.aggregate_raw_batches(
                              pipeline=aggregation_query,
)
while True:
    try:
        documents.extend([x for x in decode_all(cursor.next())])
    except StopIteration:
        break

How would I use bsonjs.dumps instead?

@ShaneHarvey
Copy link
Collaborator

This library is only useful for converting raw BSON data (eg RawBSONDocument) to MongoDB Extended JSON. If you need the documents to be decoded into Python dict then this library will not help.

Also aggregate_raw_batches is only useful when the app needs a stream of raw BSON data. If you're going to decode_all then it will be more efficient to use a regular aggregate:

documents = list(collection.aggregate(pipeline))

@ShaneHarvey
Copy link
Collaborator

For help speeding up your application I suggest posting here: https://www.mongodb.com/community/forums/tag/python

It would help to include more info about the size of the result set (how big is documents?), how long is the query vs the query decoding, what happens to documents, would it be faster to process the documents individually?, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants