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

$slice projection does not return other fields #67

Open
thasler opened this issue Dec 9, 2021 · 1 comment
Open

$slice projection does not return other fields #67

thasler opened this issue Dec 9, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@thasler
Copy link

thasler commented Dec 9, 2021

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.

@davidlatwe davidlatwe added the bug Something isn't working label Dec 9, 2021
@thasler
Copy link
Author

thasler commented Dec 9, 2021

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)

davidlatwe added a commit that referenced this issue Mar 26, 2023
For #67, thanks to @thasler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants