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

OperationError: Query for sharded findAndModify must contain the shard key #2772

Open
tzongw opened this issue Oct 5, 2023 · 0 comments
Open

Comments

@tzongw
Copy link

tzongw commented Oct 5, 2023

class User(DynamicDocument):
    name = StringField()

_id is the shard key

user.modify(name='ok')

gets this error

mongoengine.errors.OperationError: Update failed (Query for sharded findAndModify must contain the shard key, full error: {'ok': 0.0, 'errmsg': 'Query for sharded findAndModify must contain the shard key', 'code': 61, 'codeName': 'ShardKeyNotFound'})

the command log is

Command SON([('findAndModify', 'user'), ('query', {'$and': [{'_id': ObjectId('60d96a58ea9596f92ba54c7e')}, {'_id': ObjectId('60d96a58ea9596f92ba54c7e')}]}), ('new', True), ('update', {'$set': {'name': 'ok'}}), ('upsert', False)])

Environment

  • Python 3.11.2
  • mongodb 4.4.17
  • mongoengine 0.27.0
  • pymongo 4.5.0

when I use older project with same db, it works without error

the command log is

Command SON([('findAndModify', 'user'), ('query', {'_id': ObjectId('60d96a58ea9596f92ba54c7e')}), ('new', True), ('update', {'$set': {'name': 'ok'}}), ('upsert', False)])

Older Environment

  • Python 3.5.3
  • mongodb 4.4.17
  • mongoengine 0.19.0
  • pymongo 3.12.3

I notice newer version query has a $and operator, and I try it in mongo shell, gets same error.

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

No branches or pull requests

1 participant