Persisting data with MongoDB and Mongoose
MongoDB is an open source document-oriented database system. MongoDB stores structured data such as JSON-like documents, simplifying integration.
Let's start by creating a MongoDB schema for our project. The schema contains some basic information related to the project such as the project's name, a GitHub access token, a user, and a list of repositories.
Let's install Mongoose, a MongoDB Object Document Mapper for Node.js; it provides a schema-based solution to modeling your data.
npm install mongoose --save
Let's configure our application to use MongoDB and Mongoose; we add a URL for MongoDB to our configuration files ./lib/config/*.js
:
{ "express": { "port": 3000 }, "logger" : { "filename": "logs/run.log", "level": "silly" }, "mongo": { "url": "mongodb://localhost/vision" } }
Let's create a MongoDB connection module, ./lib/db/index.js
, which simply pulls in the MongoDB URL from our Winston configuration and opens a connection...