@crittercism have used _meta to set shard key data and patched save() so update works across shards.
I'll prepare the pull request later today or this weekend as I'm at MongoSV today.
Also, I need to write tests for the patch, and maybe there is a way to introspect the shard key from the database.
I'm not sure if it was a bug with _delta() or not but we also had to add some code to remove the shard keys from set_data inside _delta. We weren't changing the shard key fields but for whatever reason they still ended up in set_data.
Mongo throws an error if you issue an update that includes a $set operation on shard keys (even if the shard key values passed into the criteria are equivalent to the $set values)
I think the expected behavior for save is:
Send the shard key in the update query automatically, so it works as expected.
If you try to change the shard key, raise an exception. (or just use whatever pymongo raises)
In other words don't remove it from the delta automatically. If there's a bug in _delta, we need to fix it.
I want to avoid a weird case where you unexpectedly only save part of the changes to a document, which is what happens if you silently change the delta. That would confuse people.
We may need to fix our patch if we're modifying _delta.
I wasn't able to figure out a way to introspect the key. Probably need a documentation update as well. Basically you specify the shard key as a tuple.
Added Sharding support
Added shard_key meta, so save() and update() passes shard keys
to the pymongo query. Also made shard key fields immutable.
Closes #388 and #389
Once again - thanks for the patch @allang @andrewmlevy @crittercism