Here, I am currently learning how to use MongoDB with NodeJS, but here is 1h or 2h blocked on internet looking now for a solution with 2 errors that I have and impossible to find the problem here is my code (Sorry, I am French, in the console.log, the sentences are in fr):
var MongoClient = require('mongodb').MongoClient
const mongodbUrl = "mongodb://localhost:27017/"
let client = new MongoClient(mongodbUrl, {useNewUrlParser: true})
let essai
var randomstring = '';
test()
function test(){
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz-*/+.,?;:!§ù%$*£¤¨^=+})°]à@ç^_\è`-|(['{#é~&²";
var string_length = 14;
randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
//console.log(randomstring)
CheckBDD(randomstring)
//setTimeout(1000)
}
function CheckBDD(randomstring){
client.connect((err, client) => {
if (err) throw err
//console.log("Connexion à la bdd avec succès")
const dbName = "wordlist"
let db = client.db("wordlist")
var collection = 'wordlist';
db.collection('wordlist').findOne({wordlist: randomstring}, (err, essai) => {
if (err) throw err
//console.log(essai)
if (essai == null)
{
db.collection('wordlist').insertOne( { wordlist: randomstring} );
console.log("Valeur inconnue:" + randomstring)
} else {
console.log("Valeur déjà connue:" + randomstring)
}
test()
});
});
}
Errors:
the options [servers] is not supported
the options [caseTranslate] is not supported
From what I found, it will come from the connection options but... There you go. I hope you can help me thank you very much in advance,
Owzlaa