Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB and Mongoose Tutorial

MongoDB and Mongoose Tutorial

andikan

May 08, 2014
Tweet

More Decks by andikan

Other Decks in Programming

Transcript

  1. 3

  2. MongoDB scalable, high-performance, open source NoSQL database • document store

    • full index support • replication • querying • map / reduce 9
  3. MongoDB implemented in C++ drivers are available in many language

    http://docs.mongodb.org/manual/applications/drivers/ MongoDB Drivers and Client Libraries 10
  4. BSON Binary JSON BSON = JSON + a few additions

    • ObjectID • Timestamp • Date 11
  5. MongoDB Terminology Relational DBs MongoDB database database table collection row

    (tuple) document (BSON) column field index index primary key _id foreign key 12
  6. mongod The primary daemon process for the MongoDB system It

    handles data requests, manages data format, and performs background management operations 16
  7. Connect to mongod By default, mongo looking for a database

    server listening on port 27017 on the localhost 20
  8. Welcome to the MongoDB shell Session will use the test

    database by default Access with the Javascript Language 21
  9. Name of the current database Display the list of databases

    Switch to a new database named cooldb 23
  10. Methods to query documents Query Operators Comparison: $gt, $gte, $in,

    $lt, $lte, $ne, $nin Logical: $or, $and, $not, $nor Array: $all, $size, $eleMatch More: http://docs.mongodb.org/manual/reference/operator/query/ 30
  11. ORM Object-relational Mapper ( Relational DB ) ODM Object-document Mapper

    ( MongoDB ) validations, associations, and other high-level data modeling functions 33
  12. Mongoose Officially supported ODM for Node.js Advanced schema-based features Object

    life-cycle management Mongoose http://mongoosejs.com/ 34
  13. Create Schema - models/user.js Schema Types - String - Number

    - Date - Buffer - Boolean - Mixed - ObjectId - Array 36
  14. Postman Chrome extension A powerful HTTP Client to test web

    services http://www.getpostman.com/ 41
  15. The versionKey is a property set on each document when

    first created by Mongoose. This keys value contains the internal revision of the document. __v http://mongoosejs.com/docs/guide.html#versionKey 48
  16. Mongoose Plugins Re-use schema functionality in your own project -

    Auto increment https://github.com/codetunnel/mongoose-auto-increment - Timestamp https://github.com/drudge/mongoose-timestamp 58