When working with external storage interfaces, it can be helpful to abstract your operations behind an interface. This is for ease of mocking, portability in the event you change storage backends, and isolation of concerns. The downside to this approach may come if you need to perform multiple operations inside a transaction. In that case, it makes sense to make composite operations, or to allow them to be passed in via a context object or additional function arguments.
This recipe will implement a very simple interface for working with items in MongoDB. These items will have a name and price and we'll use an interface to persist and retrieve these objects.
Getting ready
Refer to the steps given in the Getting ready section in the Using NoSQL with MongoDB recipe.
How to do it...
These steps cover writing and running your application:
- From your Terminal or console application...