diff --git a/README.rst b/README.rst index 1290011..19bf999 100644 --- a/README.rst +++ b/README.rst @@ -1,13 +1,6 @@ -Documentation -====================== - -See: http://mongoalchemy.org/ - -This project is in maintenance mode. I'm accepting pull requests and fixing minor bugs, but you should not expect any significant new features or rearchitecting. I'm not writing any python that uses mongo these days, so I'm not keeping up with all of the most recent changes. - -With the exeption of a few issues the project is in pretty good shape and should be usable for many purposes. The most glaring issue right now is that updates and subdocuments really don't play nice together. - -I'm also happy to give the ability to commit to people who submit a lot of good pull requests. +This project is no longer maintained. Please use something else. +================================================================= +If you're interested in taking over maintenance feel free to contact me and we can discuss. diff --git a/mongoalchemy/document.py b/mongoalchemy/document.py index 0f4c072..06e0571 100644 --- a/mongoalchemy/document.py +++ b/mongoalchemy/document.py @@ -132,6 +132,13 @@ def __new__(mcs, classname, bases, class_dict): class Document(object): # __metaclass__ = DocumentMeta + __shard_key__ = None + ''' The field to specify the shard key for this collection if it is sharded. + For save operations it will look to see if this is set and use + collection.insert/update instead of collection.save because cosmos DB does + not support collection.save + ''' + mongo_id = ObjectIdField(required=False, db_field='_id', on_update='ignore') ''' Default field for the mongo object ID (``_id`` in the database). This field is automatically set on objects when they are saved into the database. @@ -222,7 +229,7 @@ def __init__(self, retrieved_fields=None, loading_from_db=False, **kwargs): self._values[name] = Value(field, self, from_db=False) else: self._values[name] = Value(field, self, from_db=False) - + # Process any extra fields for k in kwargs: if k not in fields: diff --git a/mongoalchemy/fields/fields.py b/mongoalchemy/fields/fields.py index 921ee5d..e1db642 100644 --- a/mongoalchemy/fields/fields.py +++ b/mongoalchemy/fields/fields.py @@ -133,8 +133,8 @@ def validate_wrap(self, value, *types): class IntField(NumberField): ''' Subclass of :class:`~NumberField` for ``int``''' def __init__(self, **kwargs): - ''' :param max_length: maximum value - :param min_length: minimum value + ''' :param max_value: maximum value + :param min_value: minimum value :param kwargs: arguments for :class:`Field` ''' super(IntField, self).__init__(constructor=int, **kwargs) diff --git a/mongoalchemy/ops.py b/mongoalchemy/ops.py index 4e905a0..8991d80 100644 --- a/mongoalchemy/ops.py +++ b/mongoalchemy/ops.py @@ -91,6 +91,7 @@ def __init__(self, trans_id, session, document, safe): self.data = document.wrap() self.type = type(document) self.safe = safe + self.shard_key = document.__shard_key__ # Deal with _id if '_id' not in self.data: self.data['_id'] = ObjectId() @@ -100,7 +101,18 @@ def __init__(self, trans_id, session, document, safe): def execute(self): self.ensure_indexes() kwargs = safe_args(self.safe) - return self.collection.save(self.data, **kwargs) + if self.shard_key: + # to support sharded collections the save operation needs to provide the shard key. + if self.shard_key not in self.data: + raise InvalidUpdateException('Requires shard key {} to save'.format(self.shard_key)) + _filter = { + '_id': self.data['_id'], + self.shard_key: self.data[self.shard_key] + } + kwargs['upsert'] = True + return self.collection.update(_filter, self.data, **kwargs) + else: + return self.collection.save(self.data, **kwargs) class RemoveOp(Operation): def __init__(self, trans_id, session, kind, safe, query): diff --git a/setup.py b/setup.py index a5a7c2b..cdbeeaf 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from distutils.core import setup -VERSION = '0.22.1' +VERSION = '0.22.2' DESCRIPTION = 'Document-Object Mapper/Toolkit for Mongo Databases' setup(