forked from PassTGen/PassTGenDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpasstgendb.js
42 lines (34 loc) · 1.25 KB
/
passtgendb.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
39
40
41
42
const fs=require('fs');
const mongo = require('mongodb');
const MongoClient = mongo.MongoClient;
function loadJSON(doc) {
return JSON.parse(fs.readFileSync(doc));
};
const username = encodeURIComponent("<username>"); // user you've created before
const password = encodeURIComponent("<password>"); // password you've created before
const mongoUrl = "<ip>:<port>"; // ip and port
const database = "<database>";
const authMechanism = "DEFAULT";
const uri =
`mongodb://${username}:${password}@${mongoUrl}/?authMechanism=${authMechanism}&authSource=${database}`;
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
async function run() {
try {
// Connect the client to the server
await client.connect();
var users = loadJSON('./users.json');
const resultUsers = await client.db(`${database}`).collection('users').insertMany(users);
console.dir(resultUsers.insertedCount);
var wordlist = loadJSON('./wordlist.json');
const resultWordlist = await client.db(`${database}`).collection('wordlist').insertMany(wordlist);
console.dir(resultWordlist.insertedCount);
} finally {
await client.close();
}
}
run().catch((error)=>{
console.dir(error);
});