-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulate.js
More file actions
34 lines (32 loc) · 1.3 KB
/
populate.js
File metadata and controls
34 lines (32 loc) · 1.3 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
/*jshint esversion: 6 */
var mongo = require('mongodb');
var MongoClient = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/controller';
MongoClient.connect(url, function(err, db) {
if(err) console.log("Error connecting do database");
else{
db.dropDatabase(() => {
var collection = db.collection('networks');
collection.count((err, count)=>{
if(err) console.log("Error accessing number of networks");
else{
if(count == 2) {
console.log("Networks database already up to date");
db.close();
}
else{
console.log("Inserting network entries...");
collection.insertMany([
{params: {rport:2356, broadcast_port: 2356, udplisten: true}, type: 0}, //tcp params
{params: {tty_port: "/dev/ttyUSB0"}, type: 1} //xbee 802.15.4 params
], (err, r)=>{
console.log("Done! Inserted entries: ");
console.log(r.ops);
db.close();
});
}
}
});
});
}
});