Coder Social home page Coder Social logo

erfanium / atlas_sdk Goto Github PK

View Code? Open in Web Editor NEW
41.0 41.0 7.0 35 KB

TypeSafe MongoDB Atlas Data API SDK for Deno, Deno Deploy and Node.js

Home Page: https://deno.land/x/atlas_sdk

License: MIT License

TypeScript 100.00%
atlas deno mongo-atlas mongodb sdk typescript

atlas_sdk's People

Contributors

arthur-ver avatar erfanium avatar github-actions[bot] avatar pagoru avatar pandres95 avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

atlas_sdk's Issues

By returning cursor.documents, instead of the plain cursor, there is a limit to how many documents can be returned

Source:

atlas_sdk/client.ts

Lines 99 to 115 in b9ccb49

async find(
filter?: Document,
{ projection, sort, limit, skip }: {
projection?: Document;
sort?: Document;
limit?: number;
skip?: number;
} = {},
): Promise<T[]> {
const result = await this.callApi("find", {
filter,
projection,
sort,
limit,
skip,
});
return result.documents;

I ran a find on a large collection and get 1000 documents back, even though I have more documents than that. This is because calling cursor.documents returns up to the batchSize in documents.

I think the API should instead return the plain cursor.

GridFS

I think gridfs support also can be implemented in this sdk.

UUID is not available

import { MongoClient, UUID } from "https://deno.land/x/[email protected]/mod.ts";

const client = new MongoClient({
  endpoint: "https://data.mongodb-api.com/app/YOUR_APP_ID/endpoint/data/v1",
  dataSource: "YOUR_CLUSTER_NAME",
  auth: {
    apiKey: "YOUR_API_KEY",
  },
});

await client.database("sampleDatabase").collection("sampleCollection").insertOne({
  sampleUUID: new UUID(),
})

Error when trying to create document with uuid

error: Uncaught BSONTypeError: Unrecognized or invalid _bsontype: UUID
        throw new BSONTypeError(
              ^
    at serializeDocument (https://deno.land/x/[email protected]/src/extended_json.ts:318:15)
    at serializeValue (https://deno.land/x/[email protected]/src/extended_json.ts:253:12)
    at serializeDocument (https://deno.land/x/[email protected]/src/extended_json.ts:300:22)
    at serializeValue (https://deno.land/x/[email protected]/src/extended_json.ts:253:12)
    at serializeDocument (https://deno.land/x/[email protected]/src/extended_json.ts:300:22)
    at serializeValue (https://deno.land/x/[email protected]/src/extended_json.ts:253:12)
    at Module.stringify (https://deno.land/x/[email protected]/src/extended_json.ts:469:15)
    at Collection.callApi (https://deno.land/x/[email protected]/client.ts:216:19)
    at Collection.insertOne (https://deno.land/x/[email protected]/client.ts:81:17)

fix collection type definition: `_id` field should be optional on inserts

I basically copied the example on the docs and am getting the error in the title.

code:

import {
  MongoClient,
  ObjectId,
} from "https://deno.land/x/[email protected]/mod.ts";
import { config } from "https://deno.land/x/[email protected]/mod.ts";

const client = new MongoClient({
  endpoint: `https://data.mongodb-api.com/app/${
    config().DB_APP_ID
  }/endpoint/data/v1`,
  dataSource: config().DB_DATA_SOURCE,
  auth: {
    apiKey: config().DB_API_KEY,
  },
});

interface Users {
  _id: ObjectId;
  name: string;
  email: string;
}

const db = client.database(config().DB_NAME);
const users = db.collection<Users>("users");

// error is here
users.insertOne({ // <---
  name: "John Doe",
  email: "[email protected]",
});

error:

Argument of type '{ name: string; email: string; }' is not assignable to parameter of type 'Users'.
  Property '_id' is missing in type '{ name: string; email: string; }' but required in type 'Users'.deno-ts(2345)

Update:

This was proposed by Github Copilot and seems to work:

users.insertOne({
  name: "John Doe",
  email: "[email protected]",
  _id: new ObjectId(),
});

Update:

Works:

image

publish to jsr

we need help to prepare this package to publish it to jsr
(Please ๐Ÿ‘ if you want this)

Bug in MongoDB DATA API, how to avoid it ?

Hi,

Since I have added strict validation to my model, some of my requests failed where why are encoded as application/ejson but still works as application/ejson it's looks like the bug is in mongoDB Data API, but the project is not opensource ...

to bypass the issue the request must be encoded as JSON, not EJSON.

Is that possible to force encoding to JSON ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.