Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

376
Views
Usando mongoDB con node.js con el controlador

Estoy tratando de usar mongoDB con el controlador

  1. Instalé mongoDB en Windows usando esta guía https://medium.com/@LondonAppBrewery/how-to-download-install-mongodb-on-windows-4ee4b3493514 .

  2. Creé un nuevo directorio y una app.js. (siguiendo esta guía https://docs.mongodb.com/drivers/node/master/fundamentals/connection/ ) En app.js pegué esto:

 const { MongoClient } = require("mongodb"); // Connection URI const uri = "mongodb+srv://sample-hostname:27017/?maxPoolSize=20&w=majority"; // Create a new MongoClient const client = new MongoClient(uri); async function run() { try { // Connect the client to the server await client.connect(); // Establish and verify connection await client.db("admin").command({ ping: 1 }); console.log("Connected successfully to server"); } finally { // Ensures that the client will close when you finish/error await client.close(); } } run().catch(console.dir);
  1. En la terminal, abrí mongod en el primer shell y en el segundo shell usé el comando "node app.js" dentro de su directorio.
 The terminal printed this error: C:\Users\Feder\Desktop\udemy\FruitProject\node_modules\mongodb-connection-string-url\lib\index.js:105 throw new MongoParseError('mongodb+srv URI cannot have port number'); ^ MongoParseError: mongodb+srv URI cannot have port number at new ConnectionString (C:\Users\Feder\Desktop\udemy\FruitProject\node_modules\←[4mmongodb-connection-string-url←[24m\lib\index.js:105:19) at Object.parseOptions (C:\Users\Feder\Desktop\udemy\FruitProject\node_modules\←[4mmongodb←[24m\lib\connection_string.js:210:17) at new MongoClient (C:\Users\Feder\Desktop\udemy\FruitProject\node_modules\←[4mmongodb←[24m\lib\mongo_client.js:62:46) at Object.<anonymous> (C:\Users\Feder\Desktop\udemy\FruitProject\app.js:8:16) ←[90m at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m ←[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m ←[90m at Module.load (internal/modules/cjs/loader.js:937:32)←[39m ←[90m at Function.Module._load (internal/modules/cjs/loader.js:778:12)←[39m ←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m ←[90m at internal/main/run_main_module.js:17:47←[39m
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

no use MongoDB URI en formato SRV ya que requiere un nombre de host y un nombre de dominio válido. en su caso, se está conectando con localhost que no tiene ningún nombre de dominio. en lugar de usar

 const { MongoClient } = require("mongodb"); // Connection URI const uri = "mongodb://sample-hostname:27017/?maxPoolSize=20&w=majority"; // Create a new MongoClient const client = new MongoClient(uri); async function run() { try { // Connect the client to the server const connection = await client.connect(); if(connection){ console.log("server connected successfully"); } // Establish and verify connection // await client.db("admin").command({ ping: 1 }); // console.log("Connected successfully to server"); } finally { // Ensures that the client will close when you finish/error await client.close(); } } run().catch(console.dir);

Para más información consulta esta documentación:

https://github.com/mongodb/specifications/blob/master/source/initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.rst#seedlist-discovery

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!