Mongoose介紹

jieforest發表於2012-08-06

What's Mongoose?
Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment.

Defining a model is as easy as:

CODE:

var Comment = new Schema({
    title     : String
  , body      : String
  , date      : Date
});

var BlogPost = new Schema({
    author    : ObjectId
  , title     : String
  , body      : String
  , buf       : Buffer
  , date      : Date
  , comments  : [Comment]
  , meta      : {
      votes : Number
    , favs  : Number
  }
});

var Post = mongoose.model('BlogPost', BlogPost);

Installation

The recommended way is through the excellent NPM:
$ npm install mongoose

Otherwise, you can check it in your repository and then expose it:
$ git clone git://github.com/LearnBoost/mongoose.git node_modules/mongoose/

And install dependency modules written on package.json.

Then you can require it:
require('mongoose')

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-739939/,如需轉載,請註明出處,否則將追究法律責任。