Skip to content

Misuse of coll.updateOne in MongoBackend set function #8

Description

@tobias-theobald

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions