I am newbie to mongodb and mongoose orm. I wrote a sample coffeescript to store data into mongodb, but database is not created, Here is my co开发者_高级运维de:
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
After executing the above script, db is not created in mongodb.
Am I missing anything?
Regards, gms
I saw your comment, but wanted to suggest (for others that may find this) a way to do this with comprehensions that I think is preferable. Change the last three lines from:
for person in people
artist = new artist_model person
artist_doc.insert artist
to:
artist_doc.insert new artist_model(person) for person in people
Sample how to use Mongo Model with CoffeeScript http://alexeypetrushin.github.com/mongo-model/basics.html
no need to create artist_doc
just do artist.save
精彩评论