我是mongodb和mongoose orm的新手。我寫了一個樣本的CoffeeScript將數據存儲到MongoDB中,但不創建數據庫, 這裏是我的代碼:如何使用貓鼬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是不會創建數據庫。
我錯過了什麼?
問候, 克
得到了存儲數據的解決方案,正確的代碼是: '對於人的人: artist = new artist_model person; artist.save()' – girishs