davidlatwe / montydb

Monty, Mongo tinified. MongoDB implemented in Python !

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$slice projection does not return other fields

thasler opened this issue · comments

When using the $slice projection together with an exclusion projection, the operation should return all the other fields in the document.
https://docs.mongodb.com/manual/reference/operator/projection/slice/#behavior

Monty DB is only returning the array that is sliced.

failing tests:

def test_projection_slice_6(monty_proj, mongo_proj):
    docs = [
        {"a": [0, 1, 2, 3, 4, 5, 6, 7], "x": 100, "y": 200}
    ]
    spec = {}

    def run(proj):
        monty_c = monty_proj(docs, spec, proj)
        mongo_c = mongo_proj(docs, spec, proj)

        assert count_documents(mongo_c, spec) == 1
        assert count_documents(monty_c, spec) == count_documents(mongo_c, spec)
        assert next(mongo_c) == next(monty_c)

    proj = {"a": {"$slice": [-5, 4]}, "x": 1}
    run(proj)

    proj = {"a": {"$slice": [-5, 4]}, "x": 0}
    run(proj)


def test_projection_slice_7(monty_proj, mongo_proj):
    docs = [
        {"a": [0, 1, 2, 5, 6], "b": 7, "c": 9}
    ]
    spec = {}
    proj = {"_id": 0, "a": {"$slice": 3}}

    monty_c = monty_proj(docs, spec, proj)
    mongo_c = mongo_proj(docs, spec, proj)

    assert count_documents(mongo_c, spec) == 1
    assert count_documents(monty_c, spec) == count_documents(mongo_c, spec)
    assert next(mongo_c) == next(monty_c)


def test_projection_slice_8(monty_proj, mongo_proj):
    docs = [
        {"a": [0, 1, 2, 5, 6], "b": 7, "c": 9}
    ]
    spec = {}
    proj = {"a": {"$slice": 3}}

    monty_c = monty_proj(docs, spec, proj)
    mongo_c = mongo_proj(docs, spec, proj)

    assert count_documents(mongo_c, spec) == 1
    assert count_documents(monty_c, spec) == count_documents(mongo_c, spec)
    assert next(mongo_c) == next(monty_c)