1 | import * as wmill from "https://deno.land/x/windmill@v1.19.2/mod.ts"; |
2 | import { Bson, MongoClient } from "https://deno.land/x/mongo@v0.30.1/mod.ts"; |
3 |
|
4 |
|
5 | @param: {wmill.Resource} mongodb - Resource containing mongodb connection object |
6 | example: |
7 | await client.connect({ |
8 | db: "<db_name>", |
9 | tls: true, |
10 | servers: [ |
11 | { |
12 | host: "<db_cluster_url>", |
13 | port: 27017, |
14 | }, |
15 | ], |
16 | credential: { |
17 | username: "<username>", |
18 | password: "<password>", |
19 | db: "<db_name>", |
20 | mechanism: "SCRAM-SHA-1", |
21 | }, |
22 | }); |
23 | */ |
24 |
|
25 | export async function main( |
26 | mongodb_con: wmill.Resource<"mongodb">, |
27 | db_name: string, |
28 | collection_name: string, |
29 | objectId: string |
30 | ) { |
31 | const client = new MongoClient(); |
32 |
|
33 | |
34 | const resp = await client.connect(mongodb_con); |
35 |
|
36 | const db = client.database(db_name); |
37 | const collect = db.collection(collection_name); |
38 |
|
39 | const collect_single = await collect.findOne({ _id: objectId }); |
40 |
|
41 | return (collect_single ? 'Document Found in MongoDB' : 'Document Not Found'); |
42 | } |
43 |
|