heynemann / motorengine

Motorengine is a port of MongoEngine for Tornado.
http://motorengine.readthedocs.org
204 stars 67 forks source link

Sparse fields #106

Closed etataurov closed 8 years ago

etataurov commented 8 years ago

Thanks for the great library!

Sometimes there is a need in field which is unique, but might be empty. So there is sparse index in Mongo DB, but for that index field value should not be a null, but there should not be a field in document. Now every empty field goes to database. With this new parameter empty fields won't go to database, so we will be able to use unique and sparse index for such field.

The only thing I'm not sure about - is checking for emptiness. Is 'is_empty' a good way? It is true for empty lists, but empty list is different from absence of list.

heynemann commented 8 years ago

Thanks for the contribution!

etataurov commented 8 years ago

Feels like is_empty was not a good way. Because empty string or empty list are proper values for field with sparse index. If you want to show absence of value - you will have to explicitly set it to None.

I think I need to create a PR changing is_empty check to "is None" check @heynemann what do you think?

heynemann commented 8 years ago

Sounds good to me ;)