>>> con.MyDoc.collection.update({...}, {...})
So, for the moment, you should do it manualy. I may add an
`update_document` method so we can overwrite it...
For now, if you always use the `save()` method to update your
document, you can overwrite it.
N.
On Tue, Mar 29, 2011 at 12:44 AM, Wouter <w.b.er...@gmail.com> wrote:
> Hi All,
>
> Coming from relational databases and the plethora of ORMs available
> there is one feature I am missing above all. Automatic created and
> updated timestamps on documents.
>
> The created timestamp isn't an issue as you can use default_values for
> that, but the updated timestamp you have to remember to update
> manually.
>
> Is there any easier way to do this, any 'hooks' of some sort that I
> can plugin to?
>
> Thanks,
> Wouter
https://github.com/namlook/mongokit/issues#issue/47
class BaseDocument(Document):
structure = {
'add_date': datetime.datetime,
'modify_date': datetime.datetime,
}
default_values = {
'add_date': datetime.datetime.now,
'modify_date': datetime.datetime.now
}
use_autorefs = True
use_dot_notation = True
Setting the modify_date each time is easily done by overriding the save method.
If MongoKit was to implicitely set this Nicolas would need to know and
decide exactly how it should be called.
With over 10 years experience with SQL I'm a firm believer in being
explicit and to put as much logic as you can in the same layer (e.g.
Python).
On 28 March 2011 23:44, Wouter <w.b.er...@gmail.com> wrote:
> Hi All,
>
> Coming from relational databases and the plethora of ORMs available
> there is one feature I am missing above all. Automatic created and
> updated timestamps on documents.
>
> The created timestamp isn't an issue as you can use default_values for
> that, but the updated timestamp you have to remember to update
> manually.
>
> Is there any easier way to do this, any 'hooks' of some sort that I
> can plugin to?
>
> Thanks,
> Wouter
--
Peter Bengtsson,
home www.peterbe.com
fun donecal.com
I totally agree with you. Especially with NoSQL, everything should be
explicit. For now, we can easily overwrite the save method but there's
no way to overwrite the "update" method in order to add more logic
each time we call it. Well, actually we can do it by overwriting the
Collection object but we can't create model related logic. Here's what
I have in mind :
class MyDoc(Document):
structure = {
'update_date': datetime,
}
def update_document(self, query, spec, **kwargs):
update_date = {'update_date': datetime.now()}
if '$set' in spec:
spec['$set'].update(update_date)
else:
spec['$set'] = update_date
super(MyDoc, self).update_document(query, spec, **kwargs)
this allow to inject some stuff in our atomic update query. Not only
to update_date (explicitly) but for multiple purpose...