Storing and retrieving data with Mongoskin
Mongoskin is a convenience library providing a high-level interface for mongodb
without blocking access to the existing mongodb
methods.
For this recipe, we'll re-implement the quotes
database in MongoDB using Mongoskin.
Getting ready
We'll need the mongoskin
module.
npm install mongoskin
We can also create a new folder, with a new quotes.js
file.
How to do it...
We'll require mongoskin
and use it to make a client
and a collection
instance. We don't need to create a server
instance, nor manually open the client as in the former recipe, mongoskin
takes care of that.
var mongo = require('mongoskin'); var client = mongo.db('localhost:27017/quotes'); var collection = client.collection('quotes'); var params = {author: process.argv[2], quote: process.argv[3]};
As in the previous recipe, we've defined our params
object for user input.
Instead of requiring us to use JavaScript's potentially human error prone new
keyword, mongoskin
provides a builder method (mongo...