-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Question about switch_collection #1098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, As you guessed, you can use the context_manager to temporaly switch collection. Considering the performances, you can have a look at the implementation (https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/context_managers.py), it's basically a set/reset of the Document's configuration, so it must be pretty cheap. |
Given that |
Ran into the same issue today,i know switch_collection is not thread safe now ,but I still need it ,what can be done to avoid this problem? |
@wangyushun, See here for more details. |
@samuelfekete Thanks,Your solution is perfect, but I'm not sure if it fits me.I have a Bucket table. I don't know how big the table will be in the future. Each bucket has its own collection. Dynamically create a separate class for each bucket, the dict will be large. besides, I need to remove separate class from or insert into the dict dynamically when user create or delete a bucket. I don't know if this will lead to other problems. I found PyMODM, and I'm learning about it. But now I have no other solution, I'll try your solution first. Thanks again for your reply. |
@wangyushun, if you think the number of collections will be very large, you could also consider creating the classes only when you need them. |
@samuelfekete Your solution is very good. The solution should submit to mongoengine and solved the bug. |
Any progress on this issue @MongoEngine team? |
Hi,
I'm quite new to mongodb and mongoengine and particular. We're looking at developing a multi tenanted django application that uses a single database, while giving each client their own collections for each of our models, eg:
What we would like to be able to do is easily change the collection name based on the client that using the app (each client would be assigned a collection prefix on registration). I have looked at the
switch_collection()
function, but I'm not sure if it's the best way to go about this. The site will be used by hundreds of people at the same time, so from a performance perspective I need to ensure that this does not impact negatively.The text was updated successfully, but these errors were encountered: