Mongoose?v4.8.7 發布,讓node.js更優雅的操作MongoDB
Mongoose是MongoDB的一個對象模型工具,既類似ORM,讓node.js操作MongoDB更加方便。
官方例子:
// 引入 mongoose 這個模塊
var mongoose = require('mongoose');
// 連接對應的數據庫:mongodb://localhost/test
mongoose.connect('mongodb://localhost/test');
// 創建了一個名為 Cat 的 model,mongoose 會將名詞變為復數,在這里,collection 的名字會是 `cats`。
// model定義: 有一個 String 類型的 name
var Cat = mongoose.model('Cat', {name: String});
var kitty = new Cat({ name: 'Zildjian'});
// 調用 .save 方法后,mongoose 會去你的 mongodb 中的 test 數據庫里,存入一條記錄。
kitty.save(function (err) {
if (err) {
console.log(err);
} else {
console.log('meow');
}
});
更新日志
- fix(model): if last arg in spread is falsy, treat it as a callback #5061
- fix(document): use $hook instead of hook to enable 'hook' as a path name #5047
- fix(populate): dont select foreign field if parent field is selected #5037
- fix(populate): handle passing no args to query.populate #5036
- fix(update): use correct method for casting nested arrays #5032
- fix(discriminator): handle array discriminators when casting $push #5009
下載
本站原創,轉載時保留以下信息:
本文轉自:深度開源(open-open.com)
原文地址:http://www.baiduhome.net/news/view/7890023f
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!