2
Create New Document
One script reply has been approved by the moderators Verified
Created by armancemaripota 913 days ago Viewed 10109 times
1
Submitted by adam186 Deno
Verified 716 days ago
1
import { MongoClient } from "https://deno.land/x/atlas_sdk@v1.0.3/mod.ts";
2

3
/**
4
 * @param data_source For example: `Cluster0`
5
 */
6
type MongodbRest = {
7
  endpoint: string;
8
  api_key: string;
9
};
10
export async function main(
11
  auth: MongodbRest,
12
  data_source: string,
13
  database: string,
14
  collection: string,
15
  document: Record<string, any>,
16
) {
17
  const client = new MongoClient({
18
    endpoint: auth.endpoint,
19
    dataSource: data_source,
20
    auth: { apiKey: auth.api_key },
21
  });
22
  const documents = client.database(database).collection(collection);
23
  return await documents.insertOne(document);
24
}
25

Other submissions