mongo.js
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const dboperation = require('./operations');
const jokedoc = require('./jokes/jokes.json');
const url = 'mongodb://localhost:27017/';
const dbname = 'jokeapi';
const collec = 'jokes';
var url = "mongodb://localhost:27017/jokeapi";
// Code for Creating database
// MongoClient.connect(url, function(err, db) {
// if (err) throw err;
// console.log("Database created!");
// db.close();
// });
// Code for Creating a Collection
// MongoClient.connect(url, function(err, db) {
// if (err) throw err;
// var dbo = db.db("jokeapi");
// dbo.createCollection("joke", function(err, res) {
// if (err) throw err;
// console.log("Collection created!");
// db.close();
// });
// });
//
MongoClient.connect(url).then((client) => {
console.log('Connected correctly to server');
}).catch((err)=> console.log(err));
/*
const db = client.db(dbname);
dboperation.insertDocument(db, jokedoc, collec)
.then((result) => {
console.log("Inserted Document:\n", result.ops);
return dboperation.findDocuments(db, collec);
})
.catch((err) => console.log(err));
})
*/