Skip to content

arothmel/nodetest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

10ed517 · Jan 10, 2014

History

12 Commits
Dec 8, 2013
Jan 10, 2014
Jan 10, 2014
Dec 8, 2013
Jan 10, 2014
Jan 10, 2014
Jan 10, 2014

Repository files navigation

nodeJS MongoDB test 
-------------------
based on: http://cwbuecheler.com/web/tutorials/2013/node-express-mongo/

This is a DB-driven web app !

Dependancies:
See package.json  (Note: Update package.json. See node-modules dir)

Summary:
Jade - use Jade or another templating engine to gain access to our Node/Express-based data. Jade's not hard to learn if you already know HTML. 
(Just remember that you really have to pay attention to indentation or things will go badly wrong.)

To Run on Cloud9
This caused me endless grief, that isn't really over yet:
/* --------------------------------------------------------------------
MongoDB is preinstalled in your workspace. To run MongoDB, run the following below (passing the correct parameters to it). Mongodb data will be stored in the folder data.

$ mkdir data
$ echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$@"' > mongod
$ chmod a+x mongod
---------------------------------------------------------------------*/


Start Database
---------------
MongoDB - MongoDB uses JSON for its structure. How handy is that?
$ mongod --dbpath /path/to/nodetest2/data

In another terminal 

[allison@gandalf nodetest1]$ mongo
MongoDB shell version: 2.4.6
connecting to: test
> use nodetest2
switched to db nodetest2

Insert Data
------------
db.usercollection.insert({ "username" : "fred", "phone" : "123-4567", "address" : "123 Rocky Rd.", "email" : "[email protected]" })

 db.usercollection.find().pretty()  // Pretty provides line breaks
>  db.usercollection.find().pretty()
{
	"_id" : ObjectId("52aa0eb3d044355a34033bdd"),
	"username" : "fred",
	"phone" : "123-4567",
	"address" : "123 Rocky Rd.",
	"email" : "[email protected]"
}

A quick note on DB structure: obviously in the long run you're unlikely to be storing everything at the top level. There are a ton of resources on the internet for schema design in MongoDB. Google is your friend!

newstuff = [{ "username" : "wilma", "phone" : "123-4567", "address" : "123 Rocky Rd.", "city" : "Bedrock", "email" : "[email protected]" }, 
{ "username" : "Barney", "phone" : "123-7654", "address" : "125 Rocky Rd.", "email" : "[email protected]" }]
db.usercollection.insert(newstuff);

About

A NoSQL database. Oh my!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published