Mongoose v4.5.10发布,让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> <p>// 引入 mongoose 这个模块</p> <p>var mongoose = require('mongoose');</p> <p>// 连接对应的数据库:mongodb://localhost/test</p> <p>mongoose.connect('mongodb://localhost/test');</p> <p>// 创建了一个名为 Cat 的 model,mongoose 会将名词变为复数,在这里,collection 的名字会是 `cats`。</p> <p>// model定义: 有一个 String 类型的 name</p> <p>var Cat = mongoose.model('Cat', {name: String});</p> <p>var kitty = new Cat({ name: 'Zildjian'});</p> <p>// 调用 .save 方法后,mongoose 会去你的 mongodb 中的 test 数据库里,存入一条记录。</p> <p>kitty.save(function (err) {</p> <p> if (err) {</p> <p> console.log(err);</p> <p> } else {</p> <p> console.log('meow');</p> <p> }</p> <p>});</p> <h2>更新日志</h2> <ul> <li>docs: fix typo on documents.jade #4444 <a href="/misc/goto?guid=4958993367164789620">Gabri3l</a></li> <li>chore: upgrade mocha to 3.0.2 #4437 <a href="/misc/goto?guid=4958978370978608195">TrejGun</a></li> <li>fix: subdocuments causing error with parent timestamp on update #4434 <a href="/misc/goto?guid=4958993367329170170">dyang108</a></li> <li>fix(query): don't crash if timestamps on and update doesn't have a path #4425 #4424 #4418</li> <li>fix(query): ensure single nested subdoc is hydrated when running update validators #4420</li> <li>fix(query): cast non-$geometry operators for $geoWithin #4419</li> <li>docs: update contributor count #4415 <a href="/misc/goto?guid=4958993367457176948">AdamZaczek</a></li> <li>docs: add more clarification re: the index event #4410</li> <li>fix(document): only skip modifying subdoc path if parent is direct modified #4405</li> <li>fix(schema): throw cast error if provided date invalid #4404</li> <li>feat(error): use util.inspect() so CastError never prints "[object Object]" #4398</li> <li>fix(model): dont error if the discriminator key is unchanged #4387</li> <li>fix(query): don't throw unhandled rejection with bluebird when using cbs #4379</li> </ul> <h2>下载</h2> <ul> <li><a href="/misc/goto?guid=4958993367587407315" rel="nofollow"><strong>Source code</strong> (zip)</a></li> <li><a href="/misc/goto?guid=4958993367712257347" rel="nofollow"><strong>Source code</strong> (tar.gz)</a></li> </ul> <p>本站原创,转载时保留以下信息:<br /> 本文转自:深度开源(open-open.com)<br /> 原文地址:<a href="http://www.open-open.com/news/view/7dde7e41">http://www.open-open.com/news/view/7dde7e41</a></p>