{
  "name": "mongodb",
  "version": "2.0.45",
  "description": "MongoDB legacy driver emulation layer on top of mongodb-core",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git@github.com:mongodb/node-mongodb-native.git"
  },
  "keywords": [
    "mongodb",
    "driver",
    "legacy"
  ],
  "dependencies": {
    "mongodb-core": "1.2.14",
    "readable-stream": "1.0.31",
    "es6-promise": "2.1.1"
  },
  "devDependencies": {
    "integra": "0.1.8",
    "optimist": "0.6.1",
    "bson": "~0.4",
    "jsdoc": "3.3.0-beta3",
    "semver": "4.1.0",
    "rimraf": "2.2.6",
    "gleak": "0.5.0",
    "mongodb-version-manager": "^0.7.1",
    "mongodb-tools": "~1.0",
    "co": "4.5.4",
    "bluebird": "2.9.27"
  },
  "author": {
    "name": "Christian Kvalheim"
  },
  "license": "Apache-2.0",
  "bugs": {
    "url": "https://github.com/mongodb/node-mongodb-native/issues"
  },
  "scripts": {
    "test": "node test/runner.js -t functional"
  },
  "homepage": "https://github.com/mongodb/node-mongodb-native",
  "readme": "[![NPM](https://nodei.co/npm/mongodb.png?downloads=true&downloadRank=true)](https://nodei.co/npm/mongodb/) [![NPM](https://nodei.co/npm-dl/mongodb.png?months=6&height=3)](https://nodei.co/npm/mongodb/)\n\n[![Build Status](https://secure.travis-ci.org/mongodb/node-mongodb-native.png)](http://travis-ci.org/mongodb/node-mongodb-native)\n\n[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/mongodb/node-mongodb-native?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)\n\n# Description\n\nThe MongoDB driver is the high level part of the 2.0 or higher MongoDB driver and is meant for end users.\n\n## MongoDB Node.JS Driver\n\n| what          | where                                          |\n|---------------|------------------------------------------------|\n| documentation | http://mongodb.github.io/node-mongodb-native/  |\n| api-doc        | http://mongodb.github.io/node-mongodb-native/2.0/api/  |\n| source        | https://github.com/mongodb/node-mongodb-native |\n| mongodb       | http://www.mongodb.org/                        |\n\n### Blogs of Engineers involved in the driver\n- Christian Kvalheim [@christkv](https://twitter.com/christkv) <http://christiankvalheim.com>\n\n### Bugs / Feature Requests\n\nThink you’ve found a bug? Want to see a new feature in node-mongodb-native? Please open a\ncase in our issue management tool, JIRA:\n\n- Create an account and login <https://jira.mongodb.org>.\n- Navigate to the NODE project <https://jira.mongodb.org/browse/NODE>.\n- Click **Create Issue** - Please provide as much information as possible about the issue type and how to reproduce it.\n\nBug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the\nCore Server (i.e. SERVER) project are **public**.\n\n### Questions and Bug Reports\n\n * mailing list: https://groups.google.com/forum/#!forum/node-mongodb-native\n * jira: http://jira.mongodb.org/\n\n### Change Log\n\nhttp://jira.mongodb.org/browse/NODE\n\nQuickStart\n==========\nThe quick start guide will show you how to setup a simple application using node.js and MongoDB. Its scope is only how to set up the driver and perform the simple crud operations. For more in depth coverage we encourage reading the tutorials.\n\nCreate the package.json file\n----------------------------\nLet's create a directory where our application will live. In our case we will put this under our projects directory.\n\n```\nmkdir myproject\ncd myproject\n```\n\nEnter the following command and answer the questions to create the initial structure for your new project\n\n```\nnpm init\n```\n\nNext we need to edit the generated package.json file to add the dependency for the MongoDB driver. The package.json file below is just an example and your will look different depending on how you answered the questions after entering `npm init`\n\n```\n{\n  \"name\": \"myproject\",\n  \"version\": \"1.0.0\",\n  \"description\": \"My first project\",\n  \"main\": \"index.js\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/christkv/myfirstproject.git\"\n  },\n  \"dependencies\": {\n    \"mongodb\": \"~2.0\"\n  },\n  \"author\": \"Christian Kvalheim\",\n  \"license\": \"Apache 2.0\",\n  \"bugs\": {\n    \"url\": \"https://github.com/christkv/myfirstproject/issues\"\n  },\n  \"homepage\": \"https://github.com/christkv/myfirstproject\"\n}\n```\n\nSave the file and return to the shell or command prompt and use **NPM** to install all the dependencies.\n\n```\nnpm install\n```\n\nYou should see **NPM** download a lot of files. Once it's done you'll find all the downloaded packages under the **node_modules** directory.\n\nBooting up a MongoDB Server\n---------------------------\nLet's boot up a MongoDB server instance. Download the right MongoDB version from [MongoDB](http://www.mongodb.org), open a new shell or command line and ensure the **mongod** command is in the shell or command line path. Now let's create a database directory (in our case under **/data**).\n\n```\nmongod --dbpath=/data --port 27017\n```\n\nYou should see the **mongod** process start up and print some status information.\n\nConnecting to MongoDB\n---------------------\nLet's create a new **app.js** file that we will use to show the basic CRUD operations using the MongoDB driver.\n\nFirst let's add code to connect to the server and the database **myproject**.\n\n```js\nvar MongoClient = require('mongodb').MongoClient\n  , assert = require('assert');\n\n// Connection URL\nvar url = 'mongodb://localhost:27017/myproject';\n// Use connect method to connect to the Server\nMongoClient.connect(url, function(err, db) {\n  assert.equal(null, err);\n  console.log(\"Connected correctly to server\");\n\n  db.close();\n});\n```\n\nGiven that you booted up the **mongod** process earlier the application should connect successfully and print **Connected correctly to server** to the console.\n\nLet's Add some code to show the different CRUD operations available.\n\nInserting a Document\n--------------------\nLet's create a function that will insert some documents for us.\n\n```js\nvar insertDocuments = function(db, callback) {\n  // Get the documents collection\n  var collection = db.collection('documents');\n  // Insert some documents\n  collection.insert([\n    {a : 1}, {a : 2}, {a : 3}\n  ], function(err, result) {\n    assert.equal(err, null);\n    assert.equal(3, result.result.n);\n    assert.equal(3, result.ops.length);\n    console.log(\"Inserted 3 documents into the document collection\");\n    callback(result);\n  });\n}\n```\n\nThe insert command will return a results object that contains several fields that might be useful.\n\n* **result** Contains the result document from MongoDB\n* **ops** Contains the documents inserted with added **_id** fields\n* **connection** Contains the connection used to perform the insert\n\nLet's add call the **insertDocuments** command to the **MongoClient.connect** method callback.\n\n```js\nvar MongoClient = require('mongodb').MongoClient\n  , assert = require('assert');\n\n// Connection URL\nvar url = 'mongodb://localhost:27017/myproject';\n// Use connect method to connect to the Server\nMongoClient.connect(url, function(err, db) {\n  assert.equal(null, err);\n  console.log(\"Connected correctly to server\");\n\n  insertDocuments(db, function() {\n    db.close();\n  });\n});\n```\n\nWe can now run the update **app.js** file.\n\n```\nnode app.js\n```\n\nYou should see the following output after running the **app.js** file.\n\n```\nConnected correctly to server\nInserted 3 documents into the document collection\n```\n\nUpdating a document\n-------------------\nLet's look at how to do a simple document update by adding a new field **b** to the document that has the field **a** set to **2**.\n\n```js\nvar updateDocument = function(db, callback) {\n  // Get the documents collection\n  var collection = db.collection('documents');\n  // Update document where a is 2, set b equal to 1\n  collection.update({ a : 2 }\n    , { $set: { b : 1 } }, function(err, result) {\n    assert.equal(err, null);\n    assert.equal(1, result.result.n);\n    console.log(\"Updated the document with the field a equal to 2\");\n    callback(result);\n  });  \n}\n```\n\nThe method will update the first document where the field **a** is equal to **2** by adding a new field **b** to the document set to **1**. Let's update the callback function from **MongoClient.connect** to include the update method.\n\n```js\nvar MongoClient = require('mongodb').MongoClient\n  , assert = require('assert');\n\n// Connection URL\nvar url = 'mongodb://localhost:27017/myproject';\n// Use connect method to connect to the Server\nMongoClient.connect(url, function(err, db) {\n  assert.equal(null, err);\n  console.log(\"Connected correctly to server\");\n\n  insertDocuments(db, function() {\n    updateDocument(db, function() {\n      db.close();\n    });\n  });\n});\n```\n\nRemove a document\n-----------------\nNext lets remove the document where the field **a** equals to **3**.\n\n```js\nvar removeDocument = function(db, callback) {\n  // Get the documents collection\n  var collection = db.collection('documents');\n  // Insert some documents\n  collection.remove({ a : 3 }, function(err, result) {\n    assert.equal(err, null);\n    assert.equal(1, result.result.n);\n    console.log(\"Removed the document with the field a equal to 3\");\n    callback(result);\n  });\n}\n```\n\nThis will remove the first document where the field **a** equals to **3**. Let's add the method to the **MongoClient.connect** callback function.\n\n```js\nvar MongoClient = require('mongodb').MongoClient\n  , assert = require('assert');\n\n// Connection URL\nvar url = 'mongodb://localhost:27017/myproject';\n// Use connect method to connect to the Server\nMongoClient.connect(url, function(err, db) {\n  assert.equal(null, err);\n  console.log(\"Connected correctly to server\");\n\n  insertDocuments(db, function() {\n    updateDocument(db, function() {\n      removeDocument(db, function() {\n        db.close();\n      });\n    });\n  });\n});\n```\n\nFinally let's retrieve all the documents using a simple find.\n\nFind All Documents\n------------------\nWe will finish up the Quickstart CRUD methods by performing a simple query that returns all the documents matching the query.\n\n```js\nvar findDocuments = function(db, callback) {\n  // Get the documents collection\n  var collection = db.collection('documents');\n  // Find some documents\n  collection.find({}).toArray(function(err, docs) {\n    assert.equal(err, null);\n    assert.equal(2, docs.length);\n    console.log(\"Found the following records\");\n    console.dir(docs);\n    callback(docs);\n  });\n}\n```\n\nThis query will return all the documents in the **documents** collection. Since we removed a document the total documents returned is **2**. Finally let's add the findDocument method to the **MongoClient.connect** callback.\n\n```js\nvar MongoClient = require('mongodb').MongoClient\n  , assert = require('assert');\n\n// Connection URL\nvar url = 'mongodb://localhost:27017/myproject';\n// Use connect method to connect to the Server\nMongoClient.connect(url, function(err, db) {\n  assert.equal(null, err);\n  console.log(\"Connected correctly to server\");\n\n  insertDocuments(db, function() {\n    updateDocument(db, function() {\n      removeDocument(db, function() {\n        findDocuments(db, function() {\n          db.close();\n        });\n      });\n    });\n  });\n});\n```\n\nThis concludes the QuickStart of connecting and performing some Basic operations using the MongoDB Node.js driver. For more detailed information you can look at the tutorials covering more specific topics of interest.\n\n## Next Steps\n\n * [MongoDB Documentation](http://mongodb.org/)\n * [Read about Schemas](http://learnmongodbthehardway.com/)\n * [Star us on GitHub](https://github.com/mongodb/node-mongodb-native)\n",
  "readmeFilename": "README.md",
  "_id": "mongodb@2.0.45",
  "_from": "mongodb@~2.0.45"
}
