montydb icon indicating copy to clipboard operation
montydb copied to clipboard

Support for Mongoengine

Open yamsu opened this issue 3 years ago • 2 comments

Montydb with the sqlite backend provides multi-process operation, at least in my initial trials with just 2 processes writing to the database simultaneously. This is clearly an advantage over mongita, which also provides a file/mem clone of pyMongodb; however, doesn't provide multi-process support. But mongitadb does support Mongoengine which was achieved recently.

Has anyone been able to use Montydb with Mongoengine?

yamsu avatar Oct 06 '21 10:10 yamsu

Hi @yamsu , I haven't tried with MongoEngine before, but I think you could try following the setup mentioned here https://github.com/scottrogowski/mongita/issues/4#issuecomment-825839719

Please let me know if it works or not, I will have a deeper look ASAP.

davidlatwe avatar Oct 06 '21 10:10 davidlatwe

Had a quick test and I found we need with_options and create_index implemented in Collection class at least.

davidlatwe avatar Oct 06 '21 14:10 davidlatwe

hi @davidlatwe @yamsu any update on this issue ? thanks

dodolboks avatar Jan 07 '23 14:01 dodolboks

Hey @dodolboks thanks for asking! I am not sure when I'll be back on this, will try if I can this week. Oh ands, pull requests are welcome of course, even if just some test cases. :)

davidlatwe avatar Jan 09 '23 08:01 davidlatwe

Minimum change for mongoengine support has been added into current master branch, should be released shortly.

To try out at this moment, you have to monkey-patch pymongo.MongoClient as mentioned above (https://github.com/scottrogowski/mongita/issues/4#issuecomment-825839719).

But thanks to the work in https://github.com/MongoEngine/mongoengine/pull/2729, once it's been released (probably v0.27.0), mongoengine can simply connect montydb as follow:

import montydb
import mongoengine

mongoengine.connect(db="test_db",
                    mongo_client_class=montydb.MontyClient,
                    repository=":memory:")
...

davidlatwe avatar Feb 02 '23 22:02 davidlatwe

New version released, closing this. Thanks and sorry for the long wait on this one.

davidlatwe avatar Feb 03 '23 21:02 davidlatwe