mongoose - MongoDB ODM(对象文档映射)

https://github.com/nswbmw/N-blog/wiki/%E7%95%AA%E5%A4%96%E7%AF%87%E4%B9%8B%E2%80%94%E2%80%94%E4%BD%BF%E7%94%A8-Mongoose
http://www.html5jq.com/fe/angular_node/20141230/29.html

var
mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test');
var kittySchema = mongoose.Schema({
    name: String
});

 
kittySchema.methods.speak = function () {
  var greeting = this.name
    ? "Meow name is " + this.name
    : "I don't have a name";
  console.log(greeting);
}

var Kitten = mongoose.model('Kitten', kittySchema); 
// 这里实际上生成了名叫 kittens 的集合。Kitten.collection.name
// 除了Schema定义的数据库骨架以外,还具有数据库行为模型,他相当于管理数据库属性、行为的类

var fluffy = new Kitten({ name: 'fluffy' }); // 实例化一个文档
fluffy.save() //保存到数据库
Kitten.find() // 在集合中查询