Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Instance bound to collection instead of top level document

28 views
Skip to first unread message

Victor Avramoiu

unread,
Aug 5, 2024, 9:15:43 AM8/5/24
to MongoEngine Users
Hi,

I have the following scenario: I collect data from multiple sources. The data has the same format. I want to save the date in a collection per source. The sources are dynamically determined based on configuration.

I understand that the Document class represent a Collection of elements and as such it does not make sense to have dynamic collection on it.

How can I achieve my scenario (having on element definition with collection bound to the instance not the type) ? The collection is used in multiple places from the top level document (reload, update, save, queryset etc.) and switch_collection only helps with save.

I successfully implemented the logic by haking _meta and _collection and forcing redefinition of the internal collection object but this approach is not future proof and is not thread safe.

Thank you.



Reply all
Reply to author
Forward
0 new messages