Search Documents ( mongodb)
One script reply has been approved by the moderators Verified

Created by rossumblament 243 days ago Viewed 408 times 1 Point

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import { Resource } from "https://deno.land/x/windmill@v1.55.0/mod.ts";
import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.0.1/mod.ts";
import { MongoClient } from "https://deno.land/x/atlas_sdk@v1.0.3/mod.ts";

/**
 * @param data_source For example: `Cluster0`
 *
 * @param filter For example: `{ "_id": "01234" }`
 * Find out more at:
 * https://www.mongodb.com/docs/manual/reference/method/db.collection.find/
 */
export async function main(
  auth: Resource<"mongodb_rest">,
  data_source: string,
  database: string,
  collection: string,
  filter?: Record<string, any>,
  projection?: Record<string, number>,
  sort?: Record<string, number>,
  limit?: number,
  skip?: number,
) {
  const client = new MongoClient({
    endpoint: auth.endpoint,
    dataSource: data_source,
    auth: { apiKey: auth.api_key },
  });
  const documents = client.database(database).collection(collection);
  return await documents.find(
    filter,
    removeObjectEmptyFields({ projection, sort, limit, skip }),
  );
}

Submitted by adam186 45 days ago

Edited 19 days ago

No comments yet

Login to be able to comment