Я получаю эту ошибку, когда пытаюсь подключить свое приложение (nodejs) к mongodb.Я очень ценю вашу помощь здесь.
MongoParseError: URI does not have hostname, domain name and tld
at parseSrvConnectionString (E:\Projects\NodeAPI\node_modules\mongodb-core\lib\uri_parser.js:41:21)
at parseConnectionString (E:\Projects\NodeAPI\node_modules\mongodb-core\lib\uri_parser.js:509:12)
at connect (E:\Projects\NodeAPI\node_modules\mongodb\lib\operations\mongo_client_ops.js:195:3)
at connectOp (E:\Projects\NodeAPI\node_modules\mongodb\lib\operations\mongo_client_ops.js:284:3)
at executeOperation (E:\Projects\NodeAPI\node_modules\mongodb\lib\utils.js:416:24)
at MongoClient.connect (E:\Projects\NodeAPI\node_modules\mongodb\lib\mongo_client.js:175:10)
at Function.MongoClient.connect (E:\Projects\NodeAPI\node_modules\mongodb\lib\mongo_client.js:341:22)
at Object.<anonymous> (E:\Projects\NodeAPI\server.js:12:13)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
name: 'MongoParseError',
[Symbol(mongoErrorContextSymbol)]: {} }
Мой код:
db.js
module.exports = {
uri : "mongodb+srv://mithun:*******@cluster0-s089x.mongodb.net/test?retryWrites=true"}
==================================================================
node_route.js
module.exports = function(app, db){
app.post('/notes', (req, res) => {
const note = {text: req.body.body, title: req.body.title};
db.collection('notes').insert(note, (err, results) => {
if(err){
res.send({'error': 'An error has occured'});
} else {
res.send(result.ops[0]);
}
});
});
};
================================================================================== index.js
const noteRoutes = require('./note_route');
module.exports = function(app, db){
noteRoutes(app, db);
}
============================================================================== server.js
const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');
const db = require('./config/db');
const app = express();
const port = 8000;
app.use(bodyParser.urlencoded({extended: true}));
MongoClient.connect(db.uri,{ useNewUrlParser: true }, (err, database) =>
{
if (err) return console.log(err);
require('./app/routes')(app, database);
app.listen(port, () => {
console.log("We are live on " +port);
});
});
===========================================================================
module.exports = {
uri : "mongodb+srv://mithun:m3Thun#47@cluster0-s089x.mongodb.net/test?retryWrites=true&ssl=false"
}
Я пытался с ssl = false, но ошибка остается той же.