Use monk in nodejs to access mongodb and nodejsmongodb
Install mongodb
I think mannual install is a little more reliable: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
Start mongodb
$ mongod
Connect to mogodb
$ mongomongo> use monk-appmongo> db.products.insert({"name":"apple juice", "description":"good"})WriteResult({ "nInserted" : 1 })mongo> db.products.find().pretty(){ "_id" : ObjectId("53b4cf8d5ef358e649ff1665"), "name" : "apple juce", "description" : "good"}
Access mongodb with monk in nodejs
$ mkdir monk-app$ cd monk-ap
Create package. json
{ "name": "monk-app", "version": "0.0.1", "private": true, "dependencies": { "mongodb": "*", "monk": "*" }}
$ npm install
Create app. js
Link to the database created earlier
var monk = require('monk')var db = monk('localhost:27017/monk-demo')
Read data:
var monk = require('monk')var db = monk('localhost:27017/monk-demo')var products = db.get('products') products.find({}, function(err, docs) { console.log(docs)})[ { _id: 53b4d3238cb4707ca35ab6f8, name: 'apple juice', description: 'good' } ]
Insert data:
products.insert({"name":"orange juice","description":"just so so"})
Search data:
products.find({"name":"apple juice"}, function(err, docs) { console.log(docs)})
How can other computers access their own nodejs servers?
Replace the localhost part with the ip address of your machine, for example, 192.168.1.2.
Nodejs uses multiple different mongodb databases (mongoose)
Mongoose. createConnection