1

I am new to MongoDB and python. I know how to make basic use of pymongo in order to manipulate documents.

I am having trouble finding how to create some structure or governance in what gets inside of the database.

Currently, I am storing with a dict {number:'',data:''}. Recently I wanted to change data to reg_id. I missed the change in one place, and that didnt came up until testing. It seems quite horrible that I would have to find every single place that I am accessing the data, and then change the key value of a map. Surely there must be a way or convention that is being used which works for large applications, right?

In my 700 line application it took 2 minutes to change the keys. In a 70k+ line application it would take hours to change all of them. So it seems like I'm doing something wrong.

To summarize my question:
Is using a plain dictionary the correct way of interacting with mongodb?
Or am I supposed to be using a domain-like-class to encapsulate the information I am currently putting in the dictionary?

  • It's essentially not a whole lot different from traditional RDBMS; if you reference database columns directly from a variety of different places in your source, you have to refactor all these places independently. The design pattern here is to have only one canonical place where those columns are referenced and abstract everything else around it using classes or canonical getters/setters. – deceze Mar 15 '15 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.