Skip to content

Handle Shard keys with save() #388

rozza opened this Issue Dec 9, 2011 · 5 comments

3 participants

rozza commented Dec 9, 2011

@crittercism have used _meta to set shard key data and patched save() so update works across shards.

Patch: crittercism/mongoengine@b635a97

aliang commented Dec 9, 2011

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)

aliang commented Dec 9, 2011

I think the expected behavior for save is:

  1. Send the shard key in the update query automatically, so it works as expected.

  2. 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.

aliang commented Dec 9, 2011

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.

@rozza rozza added a commit that closed this issue Dec 12, 2011
@rozza rozza 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
@rozza rozza closed this in 11daf70 Dec 12, 2011
rozza commented Dec 12, 2011

Once again - thanks for the patch @allang @andrewmlevy @crittercism

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.