meteor-reactive-aggregate icon indicating copy to clipboard operation
meteor-reactive-aggregate copied to clipboard

ReactiveAggregate() + collection.update() -> Error: Expected to find a document to change

Open anarchist912 opened this issue 6 years ago • 1 comments

I'm not sure if I'm doing something wrong or this is a bug. I've taken quite an effort to describe the problem on StackOverflow, so please allow me to simply link to my question there.

In short and for search engines:

Uncaught Error: Expected to find a document to change
    at Object.update (collection.js:207)
    at Object.store.<computed> [as update] (livedata_connection.js:310)
    ...

This (probably) gets thrown when ReactiveAggregate() tries to update the clientCollection. But I don't know what I'm doing wrong here.

anarchist912 avatar Jun 09 '19 08:06 anarchist912

I could get rid of the above mentioned error by manually giving an arbitrary string to the _id field. I had _id: 0 in the last aggregation stage before. However, contrary to the docs, simply omitting the _id field did not result in an automatic creation of this field by ReactiveAggregate().

So I did this:

...
},{
        $project: {
            _id: "whatTheFuckIsGoingOnHere", // Calm down, bro!
            rankingList: 1,
            product_keys: "$product_keys.product_keys"
        }
    }
], { clientCollection: "aggregatedProductRanking"})

I'm not sure whether I misunderstood the docs, or this is a bug. So I'm leaving this open for you guys. Thanks for this awesome package. Reactive Aggregations are the sh*t!

anarchist912 avatar Jun 10 '19 07:06 anarchist912