Mongoose v4.5.8發布,讓node.js更優雅的操作MongoDB

jopen 8年前發布 | 11K 次閱讀 MongoDB ROM Node.js mongoose

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): make changing the discriminator key cause a cast error #4374
  • fix(query): pass projection fields to cursor #4371 #4342 Corei13
  • fix(document): support multiple paths for isModified #4370 adambuczynski
  • fix(querycursor): always cast fields before returning cursor #4355
  • fix(query): support projection as alias for fields in findOneAndUpdate #4315
  • fix(schema): treat index false + unique false as no index #4304
  • fix(types): dont mark single nested subpath as modified if whole doc already modified #4224

下載

 

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!