SoftInstigate / restheart

Open Source Low-code API development framework Featuring ready-to-go Security and MongoDB API
http://softinstigate.github.io/restheart/
GNU Affero General Public License v3.0
792 stars 170 forks source link

$ifvar in change streams #500

Closed trappa92 closed 5 months ago

trappa92 commented 5 months ago

Describe the bug

$ifvar in change streams seems to not working. Is it supposed to work? if i understand, what is possible for aggregations, is possible for change streams. The actual behavior when setting the bellow stage:

"stages": [
            {
                "$match": {
                    "$or" : [ { "operationType": "insert" }, { "operationType": "update" } ]
                },
            },
            { "$ifvar": [ "fruit", { "$match": { "fullDocument::fruit": { "$var": "fruit" } } } ] },
        ],
        "uri": "live",
    },
],

Can you please help?

Thanks

ujibang commented 5 months ago

Hello @trappa92 ,

Thank you for bringing this issue to our attention. It appears from the stacktrace you provided that a Null Pointer Exception (NPE) occurs when the avars query parameter is absent. This is certainly something we need to address.

As a temporary workaround, could you please try executing the request with the ?avars={} parameter, which passes an empty object? This should help us verify if the $ifvar operator is functioning correctly when avars is explicitly set to an empty value.

Meanwhile, our team will prioritize fixing the NPE issue that arises when the avars query parameter is missing.

Additionally, I wanted to note that optional stages in the Change Stream definition, as you mentioned, are indeed available starting from version 7.6.

We appreciate your cooperation as we work to resolve this. Please let us know the outcome of using ?avars={} in your request.

trappa92 commented 5 months ago

Hello :)

thanks for your quick answer. I was not very sure for optional stages in the Change Stream definition even there is something saying it in the doc. I confirm, with "?avars={}" it works as expected!

ujibang commented 5 months ago

We already implemented the fix, it was super easy. We are going to release 7.7.2 soon

Meanwhile you can test it with the following snapshot build:

$ docker run -p 8080:8080 --rm softinstigate/restheart-snapshot:be7444e

Ps If you find our project useful, we would be delighted if you could give it a star on GitHub. It helps us a lot and motivates our team to continuously improve our work. Thanks

trappa92 commented 5 months ago

Very helpful and useful! Good work team!

ujibang commented 5 months ago

7.7.2 is out https://github.com/SoftInstigate/restheart/releases/tag/7.7.2