강상위

mongodb connect and test

node_modules
mongodb
......
......@@ -4,8 +4,9 @@
- 관심있는 인물이 출연하는 방송 프로그램을 검색하여 나만의 편성표를 만든다.
## Environment
- Backend - Node.js
- Backend - Node.js / Express
- Frontend - HTML5/CSS/Javascript
- DB - MongoDB
## Prerequisite
- Terminal Environment
......
var mongoose = require('mongoose');
mongoose.connect('mongodb://username:pwd@host/dbname');
var db = mongoose.connection;
//연결실패
db.on('error', function(){
console.log('Connection Failed!');
});
//연결 성공
db.once('open', function() {
console.log('Connected!');
});
var testSchema = mongoose.Schema
({
name: String
});
var TestModel = mongoose.model("TestModel", testSchema);
/*
var test = new TestModel({ name: "test" });
test.save(function(err, test)
{
if(err){console.log(err);}
else{console.log("Success!");}
console.log("ok4");
});
*/
TestModel.find(function(err, test){
if(err){console.log(err);}
else{
console.log(test);
}
});
//db.close()
\ No newline at end of file
This diff is collapsed. Click to expand it.
......@@ -15,6 +15,8 @@
"dependencies": {
"cheerio": "^1.0.0-rc.2",
"iconv": "^2.3.1",
"request": "^2.88.0"
"mongoose": "^5.3.14",
"request": "^2.88.0",
"selenium-webdriver": "^4.0.0-alpha.1"
}
}
......