김민욱

change for db_control location

1 +const MongoClient = require('mongodb').MongoClient;
2 +const jokedoc = require('..\\joke_data\\jokes.json');
3 +const dbname = 'jokeapi';
4 +const collec = 'jokes';
5 +const dboperation = require('..\\operations.js');
6 +var url = "mongodb://localhost:27017/jokeapi";
7 +
8 +//Create database
9 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
10 + if (err) throw err;
11 + console.log("Database created!");
12 + db.close();
13 +});
14 +
15 +//Create collection
16 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 + if (err) throw err;
18 + var dbo = db.db("jokeapi");
19 + dbo.createCollection("joke", function(err, res) {
20 + if (err) throw err;
21 + console.log("Collection created!");
22 + db.close();
23 + });
24 + });
25 +
26 +
27 +//Storing data jokes.json data into mongodb
28 +MongoClient.connect(url,{ useNewUrlParser: true }).then((client) => {
29 +
30 + console.log('Connected correctly to server');
31 +
32 +
33 + const db = client.db(dbname);
34 +
35 + dboperation.insertDocument(db, jokedoc, collec)
36 + .then((result) => {
37 + console.log("Inserted Document:\n", result.ops);
38 +
39 + return dboperation.findDocuments(db, collec);
40 + })
41 + .catch((err) => console.log(err));
42 +
43 +})
44 +.catch((err) => console.log(err));
45 +
46 +
47 +
48 +
49 +
50 +
51 +
52 +
53 +
54 +
55 +
56 +
57 +
58 +// //will encapsulate all that database operations
59 +// const assert = require('assert');
60 +
61 +// exports.insertDocument = (db, document, collection, callback) =>{
62 +// const coll = db.collection(collection);
63 +// return coll.insert(document);
64 +// };
65 +
66 +// exports.findDocuments = (db, collection, input,callback)=>{
67 +// const coll = db.collection(collection);
68 +// return coll.find({"type": input}).toArray();
69 +// }
70 +
71 +// exports.removeDocuments = (db, document , collection, callback)=>{
72 +// const coll = db.collection(collection);
73 +// return coll.deleteone(document);
74 +// }
75 +
76 +// exports.updateDocuments = (db, document , update ,collection, callback)=>{
77 +// const coll = db.collection(collection);
78 +// return coll.updateOne(document, {$set: update}, null);
79 +// }
80 +
81 +// exports.getdata = (db, document, collection, input, callback =>{
82 +// result = findDocuments(db,collection);
83 +// return result;
84 +// })
...\ No newline at end of file ...\ No newline at end of file
1 +const MongoClient = require('mongodb').MongoClient;
2 +const jokedoc = require('..\\joke_data\\Funny_story.json');
3 +const dbname = 'FunnyStoryapi';
4 +const collec = 'FunnyStory';
5 +const dboperation = require('..\\operations.js');
6 +var url = "mongodb://localhost:27017/FunnyStoryapi";
7 +
8 +//Create database
9 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
10 + if (err) throw err;
11 + console.log("Database created!");
12 + db.close();
13 +});
14 +
15 +//Create collection
16 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 + if (err) throw err;
18 + var dbo = db.db("FunnyStoryapi");
19 + dbo.createCollection("FunnyStories", function(err, res) {
20 + if (err) throw err;
21 + console.log("Collection created!");
22 + db.close();
23 + });
24 + });
25 +
26 +
27 +//Storing data jokes.json data into mongodb
28 +MongoClient.connect(url,{ useNewUrlParser: true }).then((client) => {
29 +
30 + console.log('Connected correctly to server');
31 +
32 +
33 + const db = client.db(dbname);
34 +
35 + dboperation.insertDocument(db, jokedoc, collec)
36 + .then((result) => {
37 + console.log("Inserted Document:\n", result.ops);
38 +
39 + return dboperation.findDocuments(db, collec);
40 + })
41 + .catch((err) => console.log(err));
42 +
43 +})
44 +.catch((err) => console.log(err));
1 +const MongoClient = require('mongodb').MongoClient;
2 +const jokedoc = require('..\\joke_data\\reddit_joke.json');
3 +const dbname = 'redditjoke';
4 +const collec = 'reddit';
5 +const dboperation = require('..\\operations.js');
6 +var url = "mongodb://localhost:27017/redditjoke";
7 +
8 +//Create database
9 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
10 + if (err) throw err;
11 + console.log("Database created!");
12 + db.close();
13 +});
14 +
15 +//Create collection
16 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 + if (err) throw err;
18 + var dbo = db.db("redditjoke");
19 + dbo.createCollection("redditjokes", function(err, res) {
20 + if (err) throw err;
21 + console.log("Collection created!");
22 + db.close();
23 + });
24 + });
25 +
26 +
27 +//Storing data jokes.json data into mongodb
28 +MongoClient.connect(url,{ useNewUrlParser: true }).then((client) => {
29 +
30 + console.log('Connected correctly to server');
31 +
32 +
33 + const db = client.db(dbname);
34 +
35 + dboperation.insertDocument(db, jokedoc, collec)
36 + .then((result) => {
37 + console.log("Inserted Document:\n", result.ops);
38 +
39 + return dboperation.findDocuments(db, collec);
40 + })
41 + .catch((err) => console.log(err));
42 +
43 +})
44 +.catch((err) => console.log(err));
45 +