[COMPASS-5721] Query for sharded findAndModify must contain the shard key Created: 12/Apr/22  Updated: 27/Oct/23  Resolved: 20/Jun/22

Status: Closed
Project: Compass
Component/s: Compass
Affects Version/s: 1.31.1, 1.31.2
Fix Version/s: No version

Type: Bug Priority: Major - P3
Reporter: Joel J Assignee: Le Roux Bodenstein
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10


Attachments: PNG File bug_mongodb_compass_must_contain_shard_key_1.png     PNG File bug_mongodb_compass_must_contain_shard_key_2.png     PNG File bug_mongodb_compass_must_contain_shard_key_3.png    
Documentation Changes: Not Needed

 Description   

Problem Statement/Rationale

I insert a document in a sharded collection using nodejs driver. I can update it using nodejs driver. I can't update it using compass gui.

I get the error "Query for sharded findAndModify must contain the shard key". But the record does contain the shard key and everything is valid. I don't know which query compass is sending, but it seems erratic.

Steps to Reproduce

I don't know. Maybe a simple sharded collection, sharded with method HASHED.

Expected Results

It should update.

Actual Results

Update is denied with the error "Query for sharded findAndModify must contain the shard key".

Additional Notes

Please see the screenshots. The collection "appointment" is sharded on "_where._location._country._locId" with the method "HASHED". It should work.



 Comments   
Comment by Joel J [ 15/Jun/22 ]

I see. One possibility is that the bug is fixed is the current version. A lot of releases have been made in the last weeks. Maybe something has fixed this...

I don't have the bug any more.

Comment by Le Roux Bodenstein [ 15/Jun/22 ]

I did my testing by sharding with HASH. Hard to see why the method would matter, though - the code that loads the shard keys and passes them along when updating doesn't care about that detail. My hunch was that it was something to do with the deeply nested path to the key, but haven't been able to reproduce anything there yet.

Comment by Joel J [ 15/Jun/22 ]

Hi there,

Unfortunately, I don't have the configuration any more. And I can't provide this log. Sorry.

This issue was submitted 2 months ago, and I had to find a workaround. I sharded the collection with method RANGE instead of HASH, and the bug disappeared.

In your test, do you shard the table with the method HASH? Because it may be the trigger of the bug.

Regards.

Comment by Le Roux Bodenstein [ 14/Jun/22 ]

Thank you for filing this issue. We do support updating docs with the shard key and it is supposed to just work automatically. I just tried to recreate this and all my tests so far have worked just fine. I'm thinking there might be some edge case here unique to your situation.

 

The code that loads the shard keys so we can make sure those get included does log a warning if it fails, so if you can send us your compass log file we might be able to spot something in there to help us reproduce this issue.

Generated at Wed Feb 07 22:40:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.