I'm hoping for a sanity check in my design thinking.
I'm working with a small team on a website based on a MongoDB database. There are several collections in the DB -- for example, one representing persons, and one representing polls. Persons vote in polls, and their votes are recorded in a
votes array in each poll, as a document with the person's id number and the vote they cast (e.g. yes or no). Persons have information about location and other profile info.
All the code is in Python. For purposes of extracting data from the DB for an API and for web display, I'm thinking about making a Person class and a Poll class. Each of these would have methods to get data from the other collections.
For example, a Person would have
Person.get_votes() which would go to the other collection and retrieve all the polls a person had participated in, and find the votes they cast in each one. Likewise, a Poll would have
Poll.get_persons() which would return the list of person data from the Persons collection for everyone who'd voted in that poll.
Every time a developer wants a feature to get polls or persons, they'd go through this class system, rather than accessing the database directly with pymongo queries, because the queries would be built into the classes.
Is this a standard approach? Does this promote flexibility because we can change our database easily by just changing the method implementations once? Or does it reduce flexibility because it ties everything to using those classes?