Skip to content

Support $objectToArray - #723

Merged
pcorpet merged 1 commit into
mongomock:developfrom
eiszfuchs:feature/object-to-array
Oct 27, 2021
Merged

pcorpet merged 1 commit into
mongomock:developfrom
eiszfuchs:feature/object-to-array

Conversation

@eiszfuchs

Copy link
Copy Markdown
Contributor

As I was tinkering with an aggregate pipeline I found while looking for different ways of getting all properties within a collection, I noticed my tests were failing because mongomock doesn't support $objectToArray yet.

I tried to implement the function, but I wasn't 100% sure where to put it and how to properly test it.
So please, see this more of a draft or proposal. I will work on it further, but if you like my approach and can nudge me in the right direction, I'd be glad to contribute!

Oh, also, I didn't branch off the latest develop but of the last commit that was not failing, hope this is alright!

@pcorpet

pcorpet commented Oct 14, 2021

Copy link
Copy Markdown
Member

Starting the review. For reference the spec is here.

@pcorpet pcorpet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for jumping in and contributing. Please address my comments.

Comment thread mongomock/aggregate.py Resolved
Comment thread mongomock/aggregate.py Resolved
Comment thread mongomock/aggregate.py Outdated
def _object_to_array_operation(values):
to_array = []

# Use predictable key order to be testable more easily

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test and handle the case where the arg is not a dict

Comment thread tests/test__collection_api.py Resolved
Comment thread mongomock/aggregate.py Resolved
@eiszfuchs

Copy link
Copy Markdown
Contributor Author

Thank you for your quick reply and review.
I might need a while to get back into making the requested changes, but your pointers are extremely helpful! I'll do my best!

@pcorpet

pcorpet commented Oct 15, 2021

Copy link
Copy Markdown
Member

You can rebase, I've fixed the CI pipeline

@eiszfuchs eiszfuchs closed this Oct 27, 2021
@eiszfuchs
eiszfuchs force-pushed the feature/object-to-array branch from 45ee9b4 to 3c3fe72 Compare October 27, 2021 07:58
@eiszfuchs eiszfuchs reopened this Oct 27, 2021
@eiszfuchs

Copy link
Copy Markdown
Contributor Author

Wait, why was it closed?

I rebased and changed my feature quite a lot, this time taking a lot of inspiration from the $arrayToObject operator, which I don't know how I could miss that the first time.

Let me know what you think!

@pcorpet

pcorpet commented Oct 27, 2021

Copy link
Copy Markdown
Member

Thanks for the changes!

@pcorpet
pcorpet merged commit c32b94a into mongomock:develop Oct 27, 2021
@eiszfuchs

eiszfuchs commented Oct 28, 2021 •

Copy link
Copy Markdown
Contributor Author

@pcorpet Thanks for your time and help!

I'm seeing that there is still an issue with the order of the dicts in some Python versions (which breaks CI in test_aggregate_object_to_array_with_example); not sure why this didn't show up locally.

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

Successfully merging this pull request may close these issues.

2 participants