-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinsert_mongo.js
More file actions
26 lines (22 loc) · 792 Bytes
/
Copy pathinsert_mongo.js
File metadata and controls
26 lines (22 loc) · 792 Bytes
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
var fs = require('fs');
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var filepath = 'C:/Users/Owner/Desktop/cis550-project/new.json';
var filename = filepath.replace(/^.*[\\\/]/, '').toString();
var file_ext3 = filename.substr(filename.length - 4);
var file_ext4 = filename.substr(filename.length - 5);
var file = fs.readFileSync(filepath, 'utf8');
var insertDocument = function(db, callback) {
db.collection('testCollection').insert(JSON.parse(file), function(err, result) {
assert.equal(err, null);
console.log("inserted");
callback();
});
};
var uri = 'mongodb://localhost/cis550project';
MongoClient.connect(uri, function(err, db) {
assert.equal(null, err);
insertDocument(db, function() {
db.close();
});
});