import mongodb from 'mongodb'
export default defineComponent({
props: {
mongodb: {
type: "app",
app: "mongodb",
},
collection: {
type: "string"
},
filter: {
type: "object"
}
},
async run({steps, $}) {
const MongoClient = 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)
const results = await db.collection(this.collection).find(this.filter).toArray();
$.export('results', results);
await client.close()
},
})
MongoDB uses API keys for authentication. When you connect your MongoDB account, Pipedream securely stores the keys so you can easily authenticate to MongoDB APIs in both code and no-code steps.
Before you connect to your Mongo database from Pipedream, please make sure your database is accessible from the public internet. You may need to add a firewall rule allowing connections from 0.0.0.0/0
.
Then, enter the details of your Mongo host / database below.