1

PHP Doctrine has support for bi-directional references. I wonder if MongoEngine has something similar to this, so that when, for example, I add a post of a user, I don't need to manually keep both sides synced.

I could also only store the reference on the many side of a one-to-many relationship, and use something like Post(user=user_a) to get user_a's all posts. But I would like to know the trade-offs of the two approaches. Also, how about many-to-many relationships?

Much appreciated!

322896
  • 956
  • 1
  • 9
  • 19
  • You do realize that MongoDB is not a transactional database? I.e. it's impossible to guarantee such consistency on the database level (unless you implement your own transactions). – freakish Dec 25 '14 at 18:13
  • Thanks @freakish! Yeah so I wonder how people usually achieve this bi-directional references in MongoEngine, like manually updating on both sides? Or it's simply not a common use case? I feel its convenience tho. Thanks again! – 322896 Dec 26 '14 at 03:26

0 Answers0