|
C O U R S E L E C T U R E Installing MongoDB/node.js and Hello Worlds Notes taken on June 5, 2014 by Edward Tanguay |
installing MongoDB on Mac
always use 64-bit versions
32-bit are only suitable for development
they limit total amount of data to 4 GB
stable releases are always even, e.g. 2.6.0
tar xvf mongodb-osx-x86_64-2.6.0.tgz
bin where the action is
mongo is shell to connect database
not good for production of course
listening on port 27017 (default)
db.names.insert({'name':'Joe'})
always 64-bit if you can
wmic os get osarchitecture
\data\db does not exist
db.names.insert({'name':'Joe'})
introduction to Mongo shell
use demo (creates it since it doesn't exist)
db.things.insert({'a':1, 'b': 2, 'c': 3})
db.things.insert({'d':4, 'e': 5})
db.things.find({'a':1})
we are in a complete javascript environment, so we can do anything that is supported by the V8 javascript engine
for (var i = 0; i <= 10; i++) { db.things.insert({'x':i})}
ObjectId field unique across system
many different value types
you can have same keys with different types
nested array: 'colors' : ['red','black']
nested object (with attributes with key/values)
students with names and activities
you can show it like a javascript object
and modifty it as a json object
console.log("hello world");
go to: C:\Program Files\nodejs\
console.log('hello world');
asynchronous vs. synchronous
two ways of handling operations that don't require active work on the currently running thread or process
usually these are referring to IO
mongo shell is synchronous while node.js is asynchronous
var doc = db.coll.findOne();
overhead code to connect to db
not getting a return value but passing a callback function, passing an err and document value
advantage of asynchronous is that it can handle a large number of users
the mongo shell blocks other users until the values come back from the db
helloworld server in node.js
console.log('testing');
var http = require('http');
var server = http.createServer(function (request, response) {...
then http://localhost:8000/
see: howtonode.org/hello-node