This works fine, but there are a few issues with it:
- The map-reduce is run every time the page is hit. Since a variation of this method is used to provide a list of common tags for the home page of the site, this is definitely less than ideal.
- When a map-reduce function is run in MongoDB, by default the results are stored in a temporary collection which is cleaned up once the connection to MongoDB is closed, or when it is explicitly dropped – which I am not doing. Like the above issue, having to explicitly delete the collection on every page hit seems like excessive work. However leaving it as I currently am causes all these temporary collections to build up whilst the site is running. What a waste of space.
Mark Embling is actually looking to get the CouchDB MapReduce behavior with MongoDB.
Original title and link: Using Map-Reduce in a MongoDB Based Application (NoSQL databases © myNoSQL)