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

Unexpected error in aggregation $multiply #871

Open
shai-katzir-hs opened this issue Jan 11, 2024 · 0 comments
Open

Unexpected error in aggregation $multiply #871

shai-katzir-hs opened this issue Jan 11, 2024 · 0 comments

Comments

@shai-katzir-hs
Copy link

issue

Getting an AssertionError on a $multiply aggregation, which is not compatible with pymongo

Aggregation:

collection.aggregate([
        {"$match": {'some_id': 1}},
        {'$project': {'_id': {'some_id': 'some_id'}, 'max_score': {'$multiply': [bson.Decimal128("34"), 8]}}}
    ])

Exception:

AssertionError: $multiply only uses numbers

reproduce

import datetime
import mongomock
import bson
import pymongo
import pytest

@pytest.mark.parametrize("name,db", [('pymongo', pymongo.MongoClient().db),  ('mongomock',mongomock.MongoClient().db)])
def test_increase_votes_pymongo(name, db):
    collection = db['collection']
    collection.insert_one({
        'date_applied': datetime.datetime.now(tz=datetime.timezone.utc),
        'some_id': 1
    })
    print(list(collection.aggregate([
        {"$match": {'some_id': 1}},
        {'$project': {'_id': {'some_id': 'some_id'}, 'max_score': {'$multiply': [bson.Decimal128("34"), 8]}}}
    ])))

will fail on MongoMock only

additional info

versions:
pymongo==4.6.1 mongomock==4.1.2

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

1 participant