[SERVER-3608] Sharding on geo sometimes fails due to shard key being too big Created: 16/Aug/11  Updated: 06/Apr/23  Resolved: 16/Aug/11

Status: Closed
Project: Core Server
Component/s: Geo, Index Maintenance, Sharding
Affects Version/s: 1.9.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Christian Tonhäuser Assignee: Mathias Stearn
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3586 Array as shard key value should be pr... Closed
Operating System: ALL
Participants:

 Description   

When writing objects with big arrays of geo coords, the writes will often fail with "Shard Key must be less than 512 bytes" error message.
This only happens in a sharded environment, obviously, when writing to e.g. a single replica set without sharding everything's fine.



 Comments   
Comment by Christian Tonhäuser [ 17/Aug/11 ]

Hi Mathias,

thanks for your reply. Sharding by ID is exactly what we'll be doing for the time being.
However, once queries can be routed by geo shard key I'll have to look for another solution.

Comment by Mathias Stearn [ 16/Aug/11 ]

The real issue is that sharding on an array is invalid because a doc could live on more than one shard. Unfortunately we don't check for this at the moment.

Also, sharding on geo will probably not do what you want. I'd suggest just sharding on ID.

Comment by Christian Tonhäuser [ 16/Aug/11 ]

Sorry, forgot something:
The shard key is defined as

{"coordinates":1, "_id":1}

, with coordinates being an array of spatial coordinates [[lon, lat, alt],[lon,lat,alt],...]
A compound index exists on these fields as well:

{"coordinates":"2d","_id":1}
Generated at Thu Feb 08 03:03:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.