Mongoose v4.5.9发布,让node.js更优雅的操作MongoDB
jopen 8年前
<p style="text-align: center;"><img alt="" src="https://simg.open-open.com/show/8b6dbbafd94e5f9bf087b7a0b31ef2d4.jpg" /></p> <p>Mongoose是MongoDB的一个对象模型工具,既类似ORM,让node.js操作MongoDB更加方便。</p> <p>官方例子:</p> <pre> <code class="language-javascript">// 引入 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'); } });</code></pre> <h2>更新日志</h2> <ul> <li>docs: add mixed schema doc for Object literal #4400 <a href="/misc/goto?guid=4958993228261898662">Kikobeats</a></li> <li>fix(query): cast $geoWithin and convert mongoose objects to POJOs before casting #4392</li> <li>fix(schematype): dont cast defaults without parent doc #4390</li> <li>fix(query): disallow passing empty string to findOne() #4378</li> <li>fix(document): set single nested doc isNew correctly #4369</li> <li>fix(types): checks field name correctly with nested arrays and populate #4365</li> <li>fix(drivers): make debug output copy-pastable into mongodb shell #4352</li> <li>fix(services): run update validators on nested paths #4332</li> <li>fix(model): handle typeKey with discriminators #4339</li> <li>fix(query): apply timestamps to child schemas when explicitly specified in update #4049</li> <li>fix(schema): set prefix as nested path with add() #1730</li> </ul> <h2>下载</h2> <ul> <li><a href="/misc/goto?guid=4958993228369219851" rel="nofollow"><strong>Source code</strong> (zip)</a></li> <li><a href="/misc/goto?guid=4958993228480042399" rel="nofollow"><strong>Source code</strong> (tar.gz)</a></li> </ul> <p> </p> <p>本站原创,转载时保留以下信息:<br /> 本文转自:深度开源(open-open.com)<br /> 原文地址:<a href="http://www.open-open.com/news/view/43b82681">http://www.open-open.com/news/view/43b82681</a></p>