I'm new in MongoDB, and I would like to know if there is a way to create a dynamic view inside MongoDB.
Let me be more precise: In mongo I have a collection with financial data, and an GUI interface which displays the data. But each users could reduce the data by adding or removing columns to the grid, and filter the grid: a classic use case.
What I would like to do, is to create a collection for each user that listens to the master table, according to the users filters: something like this:
mongo.createView(masterCollection, filters, mapReduce)
In this scenario, mongo updates each view, each time a modification is done in the master collection (update, delete, insert).
I could do something like this manually: create a table for a user, and use a tailable cursor on my master collection with the user filters and mapReduce, and the add, remove, or update the document in the user collection.
But, I have up to 100 simultaneous users, and it would open and keep alive 100 tailable cursors on the primary collection. I don't know enough mongo, but I think it's not a best practice to do something like this.
Actually I have a thread for each user that get data for the collection, according to the user filters, every 5 seconds.
Could you please let me now if there is a native mongo way to handle this scenario or a way to create a user view in mongo.
Thank you
MongoDB Enterprise has a feature called 'Single View' which implements database views. It's more for aggregating data from multiple tables (e.g. parent/child relationships), and may be more than what you're looking for but is worth checking out. The downside, it's only available in the pricey Enterprise edition.
Check out the description here