'Pipedream's MongoDB API connection not working?
https://www.pipedream.com has an UI-assisted integration with MongoDB. It requires 4 values to connect to the API:
$username
$password
$database
$hostname
my default connect to app connection string is: mongodb+srv://<username>:<password>@cluster0.45xcf.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
(yes, I'm using the default cluster0 and myFirstDatabase values here)
I get back this error response:
MongoAPIError
URI must include hostname, domain name, and tld
DETAILS
at null.resolveSRVRecord (/tmp/ee/c_m4fDxGe5/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/connection_string.js:51:25)
at null.connect (/tmp/ee/c_m4fDxGe5/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/operations/connect.js:32:57)
at null.null (/tmp/ee/c_m4fDxGe5/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/mongo_client.js:127:35)
at null.maybePromise (/tmp/ee/c_m4fDxGe5/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/utils.js:409:5)
at MongoClient.connect (/tmp/ee/c_m4fDxGe5/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/mongo_client.js:126:41)
at Function.connect (/tmp/ee/c_m4fDxGe5/node_modules/.pnpm/[email protected]/node_modules/mongodb/lib/mongo_client.js:190:36)
at Object.run (/steps/mongodb.js:19:38)
at global.executeComponent (/var/task/launch_worker.js:171:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:653:28)
I'm trying to connect to the API with:
$username = {REDACTED}
$password = {REDACTED}
$database = myFirstDatabase
$hostname = cluster0
and it's not able to connect, but it does work connecting via mongosh, Compass, etc
here's the full Node.js code Pipedream uses to connect to MongoDB's API:
module.exports = defineComponent({
props: {
mongodb: {
type: "app",
app: "mongodb",
}
},
async run({steps, $}) {
const MongoClient = require('mongodb').MongoClient
const {
database,
hostname,
username,
password,
} = this.mongodb.$auth
const url = `mongodb+srv://${username}:${password}@${hostname}/test?retryWrites=true&w=majority`
const client = await MongoClient.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true
})
const db = client.db(database)
// Enter your target collection as a parameter to this step
this.res = await db.collection(params.collection).insertOne({ name: "Luke Skywalker" })
await client.close()
},
})
Just don't understand why it won't connect. I can confirm the username and password aren't the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
