1
Search Documents
One script reply has been approved by the moderators Verified
Created by rossumblament 930 days ago Viewed 11127 times
0
Submitted by adam186 Deno
Verified 732 days ago
1
import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.0.1/mod.ts";
2
import { MongoClient } from "https://deno.land/x/atlas_sdk@v1.0.3/mod.ts";
3

4
/**
5
 * @param data_source For example: `Cluster0`
6
 *
7
 * @param filter For example: `{ "_id": "01234" }`
8
 * Find out more at:
9
 * https://www.mongodb.com/docs/manual/reference/method/db.collection.find/
10
 */
11
type MongodbRest = {
12
  endpoint: string;
13
  api_key: string;
14
};
15
export async function main(
16
  auth: MongodbRest,
17
  data_source: string,
18
  database: string,
19
  collection: string,
20
  filter?: Record<string, any>,
21
  projection?: Record<string, number>,
22
  sort?: Record<string, number>,
23
  limit?: number,
24
  skip?: number,
25
) {
26
  const client = new MongoClient({
27
    endpoint: auth.endpoint,
28
    dataSource: data_source,
29
    auth: { apiKey: auth.api_key },
30
  });
31
  const documents = client.database(database).collection(collection);
32
  return await documents.find(
33
    filter,
34
    removeObjectEmptyFields({ projection, sort, limit, skip }),
35
  );
36
}
37

Other submissions