Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 713 Bytes

mongoose.md

File metadata and controls

39 lines (28 loc) · 713 Bytes

Mongoose

node.js mongodb 库

Built-in Promises

mongoose 默认返回的是 mpromise, mongoose推荐使用原生的 global.Promise 或者第三方的promise,例如: require('bluebird')

自定义 _id

var Post = new mongoose.Schema({
    _id: Number,
    title: String,
    content: String,
    tags: [ String ]
});

OR

var Post = new mongoose.Schema({
    title: String,
    content: String,
    tags: [ String ]
}, { _id: false });

array to json

lean()

Collection.find().lean();