Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MongoClient = require('mongodb').MongoClient
- , assert = require('assert');
- var utils = require("./utils");
- var fs = require("fs");
- utils.log("Connecting to Mongodb..");
- readfile = fs.readFileSync("config.json");
- var config = JSON.parse(readfile);
- if (config.mongo && config.mongo.user != "" && config.mongo.pass != ""); {
- var user = config.mongo.user;
- var pass = config.mongo.pass;
- // Connection URL
- var url = 'mongodb://' + user + ':' + pass + '@ds012678.mlab.com:12678/onlyprofitbot';
- }
- // Use connect method to connect to the server
- function connectMongo(client) {
- var client;
- MongoClient.connect(url, function (err, client) {
- if (err) {
- throw err;
- } else {
- utils.log("Connected to MongoDB!")
- return client;
- };
- });
- }
- savetoMongo();
- var delegator = {
- "title": "fucku",
- "help":"nothing"
- }
- function savetoMongo() {
- var connect = new Promise(function (resolve, reject) {
- resolve = connectMongo();
- });
- connect.then(function (client) {
- var db = client.db("onlyprofitbot");
- var collection = db.collection("delegators");
- collection.insert(delegator, function (err, res) {
- if (err) { throw err; }
- else {
- utils.log("Data saved to Mongodb!");
- db.close();
- return
- };
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement