Thanks to visit codestin.com
Credit goes to hub.windmill.dev

Search Documents
Codestin Search App Verified
Created by rossumblament 1310 days ago Picked 12 times
Submitted by adam186 Deno
Verified 244 days ago
1
import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
2
import { MongoClient } from "https://deno.land/x/[email protected]/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