강상위

mongodb connect and test

1 node_modules 1 node_modules
2 +mongodb
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
4 - 관심있는 인물이 출연하는 방송 프로그램을 검색하여 나만의 편성표를 만든다. 4 - 관심있는 인물이 출연하는 방송 프로그램을 검색하여 나만의 편성표를 만든다.
5 5
6 ## Environment 6 ## Environment
7 -- Backend - Node.js 7 +- Backend - Node.js / Express
8 - Frontend - HTML5/CSS/Javascript 8 - Frontend - HTML5/CSS/Javascript
9 +- DB - MongoDB
9 10
10 ## Prerequisite 11 ## Prerequisite
11 - Terminal Environment 12 - Terminal Environment
......
1 +var mongoose = require('mongoose');
2 +mongoose.connect('mongodb://username:pwd@host/dbname');
3 +var db = mongoose.connection;
4 +
5 +//연결실패
6 +db.on('error', function(){
7 + console.log('Connection Failed!');
8 +});
9 +//연결 성공
10 +db.once('open', function() {
11 + console.log('Connected!');
12 +});
13 +
14 +
15 +
16 +var testSchema = mongoose.Schema
17 +({
18 + name: String
19 +});
20 +
21 +var TestModel = mongoose.model("TestModel", testSchema);
22 +
23 +/*
24 +var test = new TestModel({ name: "test" });
25 +
26 +test.save(function(err, test)
27 +{
28 + if(err){console.log(err);}
29 + else{console.log("Success!");}
30 + console.log("ok4");
31 +});
32 +*/
33 +
34 +TestModel.find(function(err, test){
35 + if(err){console.log(err);}
36 + else{
37 + console.log(test);
38 + }
39 +});
40 +
41 +
42 +//db.close()
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 "dependencies": { 15 "dependencies": {
16 "cheerio": "^1.0.0-rc.2", 16 "cheerio": "^1.0.0-rc.2",
17 "iconv": "^2.3.1", 17 "iconv": "^2.3.1",
18 - "request": "^2.88.0" 18 + "mongoose": "^5.3.14",
19 + "request": "^2.88.0",
20 + "selenium-webdriver": "^4.0.0-alpha.1"
19 } 21 }
20 } 22 }
......