Misuse of coll.updateOne in MongoBackend set function
Hi there,
When I try to use the MongoBackend for a cache, I get the following error message:
message: the update operation document must contain atomic operators.
stack:
- MongoError: the update operation document must contain atomic operators.
- at Function.MongoError.create (/myapp/node_modules/mongodb-core/lib/error.js:45:10)
- at toError (/myapp/node_modules/mongodb/lib/utils.js:149:22)
- at checkForAtomicOperators (/myapp/node_modules/mongodb/lib/collection.js:852:12)
- at Collection.updateOne (/myapp/node_modules/mongodb/lib/collection.js:826:13)
- at /myapp/node_modules/stow/backends/mongo.js:40:18
- at MongoBackend.checksum (/myapp/node_modules/stow/backends/mongo.js:93:5)
- at MongoBackend.set (/myapp/node_modules/stow/backends/mongo.js:32:11)
- at Cache.set (/myapp/node_modules/stow/stow.js:53:16)
Looking at the code in that place, you're not using a $set operator in you update operation to replace the entire document. Changing the method from updateOne to replaceOne fixes the issue. I'm opening a PR in a minute.
I'm using MongoDB client library v3.0.8, I believe this might be the source of the issue. Your tests run against an older version (2.1.18), so they might fail.
Hey @Tobi042, apologies for the delayed response. As I am working at a different company on different projects now, I don't use or really maintain this anymore. I'd be happy to give you commit access and npm access if you're interested. I'd only ask that any new changes get major-versioned so old projects continue to work.