-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.js
38 lines (29 loc) · 893 Bytes
/
insert.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
37
38
var mongo = require('mongodb');
var mtgJson = require('./seeds/others/AllCards-X2.json');
var MongoClient = require('mongodb').MongoClient
, assert = require('assert');
var insertDocuments = function(db, data, callback) {
// Get the documents collection
var collection = db.collection('mtgcards');
// Insert some documents
console.log(data.size);
for (var key in data){
// console.log(key);
collection.insert(data[key], function(err, result) {
console.log(err);
callback(result);
});
}
}
// Connection URL
var url = 'mongodb://localhost:27017/mtg_cards';
// Use connect method to connect to the Server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server");
// db.createCollection("mtgcards");
// db.createCollection("myMTGLibrary");
insertDocuments(db, mtgJson, function(){
db.close();
});
});