Designing trees in mongodb using mongodm
08 Oct 2010
why mongodm?
mongodm is a small API on top of pymongo that allowed to create user defined mongodb object documents.
All collection’s queries are still made using pymongo, mongodm just provide an nice way to create data structures and validation schemas.
The first reason that bring me away from the great mongoengine is that’s there’s no way to easily manage recursive trees.
Here are two tree pattern implementation using this small library.
Full Tree in Single Document
code sample:
mongodb data:
Materialized paths pattern
code sample:
mongodb data:
you can easily get back children using TreeDocument.children property.
I’m working on mongodm on my time off for a personnal project (this is one of my first python developments), so feel free to give me your feed back.