0.0.1-alpha.8 • Published 2 years ago

mongorpc-js v0.0.1-alpha.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

mongorpc-js

  • Get Document
const client = new MongoRPC("http://localhost:8080");

const document = await client
  .database("sample_mflix")
  .collection("movies")
  .document("573a13b0f29313caabd35231")
  .get();

console.log(document);
  • Get All Documents from Collection
const documents = await client
  .database("sample_mflix")
  .collection("movies")
  .documents()
  .limit(10)
  .skip(10)
  .sort({
    field: "title",
    asending: false,
  })
  .get();

console.log(documents);
const documents = await client
  .database("sample_mflix")
  .collection("movies")
  .documents()
  .where({
    field: "year",
    equalTo: 1915,
  })
  .get();
  • List All Collections in Database
const collections = await client
  .database("sample_mflix")
  .listCollections();
  • Insert Document
const document = await client
  .database("sample_mflix")
  .collection("movies")
  .insert({
    title: "Blacksmith Scene",
    year: 1893,
    createdAt: Date(),
  });
  • Update Document
const result = await client
  .database("sample_mflix")
  .collection("movies")
  .document("617ba6bb72d7eadace3a5353")
  .update({
    title: "Batman Begins",
    year: 2005,
    createdAt: Date(),
  });
  • Listening for Collection Changes
const canclationToken = client
  .database("sample_mflix")
  .collection("movies")
  .listen(async (change) => {
    console.log({ change: change });
  });