0
콜렉션이 존재하지 않으면 생성하고 데이터로 미리 채우기 만한다는 간단한 검사입니다. 이 내 로컬 상자에서 제대로 작동하고 coll "존재하지 않는 경우 오류를 throw합니다 db.collection 호출에 설정된"엄격한 "플래그에 따라 달라집니다. 그러나 Heroku에서는 작동하지 않습니다.Heroku에서 strict 플래그가 작동하지 않는 db.collection 사용
mongo.Db.connect(mongoUri, function (err, db) {
if (!err)
{
console.log("Connected to Database")
db.collection('collectionName', {strict:true}, function(er, collection) {
if (!er)
{
console.log("Collection opened, ready for use!")
} else {
console.log("DATA DOES NOT EXIST, PREPOPULATING")
populateDB();
}
});
} else {
console.log("Error connecting to database: " + err)
}
});
package.json
{
"name": "appname",
"description": "Application",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x",
"mongodb": "1.3.x",
"socket.io": "0.9.10"
},
"engines": {
"node": "0.8.4",
"npm": "1.1.49"
}
}