【发布时间】:2011-10-29 13:00:32
【问题描述】:
我是 mongodb 和 mongoose orm 的新手。我写了一个示例咖啡脚本来将数据存储到 mongodb 中,但是没有创建数据库, 这是我的代码:
mongoose = require('mongoose')
db = mongoose.connect('mongodb://localhost/test')
people = [{
bio: 'hello1'
first_name: 'jay'
last_name: 'roger'
},{
bio: 'hello2'
first_name: 'jay'
last_name: 'roger'
}]
artist_schema = new mongoose.Schema
bio: String
first_name: String
last_name: String
artist_model = mongoose.model "artist", artist_schema
artist_doc = new mongoose.Collection 'artists', db
for person in people
artist = new artist_model person
artist_doc.insert artist
执行上述脚本后,mongodb中并没有创建db。
我错过了什么吗?
问候, 通用汽车
【问题讨论】:
-
得到了存储数据的解决方案,正确的代码是:
for person in people: artist = new artist_model person; artist.save()
标签: mongodb coffeescript mongoose