-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparseJsonArray.js
36 lines (32 loc) · 1.02 KB
/
parseJsonArray.js
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
// Retrieve
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/open_shakespeare", function(err, db) {
if(!err) {
console.log("connected successfully to mongodb://localhost:27017/open_shakespeare");
parseAnnotations(db);
} else {
console.error("Error connecting to mongodb://localhost:27017/open_shakespeare");
}
});
function parseAnnotations(db) {
var annotations = db.collection('annotations');
annotations.find().toArray(function(err, results) {
if(!err) {
console.log('query returned', results);
results[0].hits.hits.forEach(function(annotation){
annotations.insert(annotation, {safe: true}, function(err, records){
if(!err) {
console.log("Record added as "+records[0]._id);
} else {
console.error("error")
}
});
});
db.close();
console.log("Db closed");
} else {
console.error("Error querying annotations collection:", err );
}
});
}