moscajs / aedes-persistence-mongodb

MongoDB persistence for Aedes
MIT License
14 stars 16 forks source link

Update document requires atomic operators #48

Closed simonnilsson closed 4 years ago

simonnilsson commented 4 years ago

System Information

Describe the bug mongodb module throws this error when making a subscription from client:

TypeError: Update document requires atomic operators
    at FindOperators.updateOne (node_modules\mongodb\lib\bulk\common.js:647:13)
    at node_modules\aedes-persistence-mongodb\persistence.js:279:19
    at Array.forEach (<anonymous>)
    at MongoPersistence.addSubscriptions (node_modules\aedes-persistence-mongodb\persistence.js:270:6)
    at SubState.storeSubscriptions (node_modules\aedes\lib\handlers\subscribe.js:108:29)
    at work (node_modules\fastfall\fall.js:105:23)
    at Aedes.authorizeSubscribe (src\components\auth.js:141:3)
    at SubState.authorize (node_modules\aedes\lib\handlers\subscribe.js:80:17)
    at Holder.work (node_modules\fastfall\fall.js:105:23)
    at SubState.compiled (node_modules\fastfall\fall.js:55:17)
    at SubscribeState.doSubscribe (node_modules\aedes\lib\handlers\subscribe.js:71:16)
    at goResultsFunc (node_modules\fastparallel\parallel.js:63:16)
    at Aedes.parallel [as _parallel] (node_modules\fastparallel\parallel.js:33:9)
    at handleSubscribe (node_modules\aedes\lib\handlers\subscribe.js:61:17)
    at handle (node_modules\aedes\lib\handlers\index.js:34:7)
    at Parser.enqueue (node_modules\aedes\lib\client.js:357:5)
    at Parser.emit (events.js:311:20)
    at Parser._newPacket (node_modules\mqtt-packet\parser.js:669:10)
    at Parser.parse (node_modules\mqtt-packet\parser.js:41:41)
    at TLSSocket.nextBatch (node_modules\aedes\lib\client.js:84:24)
    at TLSSocket.emit (events.js:311:20)
    at emitReadable_ (_stream_readable.js:562:12)
simonnilsson commented 4 years ago

This error seems to have been added in mongodb driver 3.6.0, released 4 days ago. https://github.com/mongodb/node-mongodb-native/releases/tag/v3.6.0

[NODE-2660] - Throw an error if bulk update documents don't contain update operator expressions

So this module needs to declare required version to be less than 3.6.0 or update code to do this correctly.

simonnilsson commented 4 years ago

Made a pull-request with fix #49.

Looks like tests fail on other unchanged code, they pass when I run them locally.

robertsLando commented 4 years ago

@simonnilsson Tests are passing. What kind of error you got?

simonnilsson commented 4 years ago

@robertsLando Not sure, github said checks failed but now they say all passed. May have been a temporary glitch.

robertsLando commented 4 years ago

@simonnilsson This fix is available in version 8.1.0 on npm now, thanks :pray: