import mongoose from "mongoose";

import config from '../etc/config.json';

import { Word } from './models/Word';

//const Word = mongoose.model('Word');

export function setUpConnection() {
    mongoose.connect(`mongodb://${config.db.host}:${config.db.port}/${config.db.name}`);
}

export function listWords(id) {
    return Word.find();
}

export function addWord(data) {
  console.log(data);
    const word = new Word({
        eng: data.eng,
        rus: data.rus
    });
console.log(word);
    return word.save();
}

@@ -152,130 +152,365 @@
 );%0A%0A
-export function setUpConnection() %7B%0A    mongoose.connect(%60mongodb://$%7Bconfig.db.host%7D:$%7Bconfig.db.port%7D/$%7Bconfig.db.name%7D%60
+const databaseUri = process.env.MONGOLAB_URI %7C%7C%0A                    process.env.MONGOHQ_URL %7C%7C%0A                    %60mongodb://$%7Bconfig.db.host%7D:$%7Bconfig.db.port%7D/$%7Bconfig.db.name%7D%60;%0A%0Aexport function setUpConnection() %7B%0A    mongoose.connect(databaseUri, (err, res) =%3E %7B%0A      if (err) %7B console.log ('ERROR connecting to: ' + uristring + '. ' + err); %7D%0A    %7D
 );%0A%7D

set database connection url