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

Misuse of coll.updateOne in MongoBackend set function #8

Open
tobias-theobald opened this issue May 16, 2018 · 2 comments · May be fixed by #9
Open

Misuse of coll.updateOne in MongoBackend set function #8

tobias-theobald opened this issue May 16, 2018 · 2 comments · May be fixed by #9

Comments

@tobias-theobald
Copy link

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.

@tobias-theobald
Copy link
Author

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.

@cpsubrian
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants