Giter VIP home page Giter VIP logo

mongo-broker's Introduction

Mongo Broker

GitHub Page

Mongo Broker creates a RESTful API MongoDB Broker for your lovely fetch requests. To add your mongo database, in the .env file include your MongoDB SRV connection string as "mongoURI." Example:

mongoURI=mongodb+srv://<USER>:<PASSWORD>@console-uk17x.gcp.mongodb.net/test?retryWrites=true

and to accept your fetch requests, include a client auth token in your .env file as the following:

AUTHKEY=<Some random digits>

Than in your fetch requests include the header:

  {
    Authorization: <Authkey>
  }

To retrieve documents, use a GET request, with the query parameters acting as the filter. Example:

  https://mongo-broker.glitch.me/sampleDatabase/users?fname=Tom&lname=Tommerson

The above query would return Tom Tommerson's record.

If you send a get request with a query on the _id, it will always return the document object, otherwise it returns an array of document objects.

The query parameters must be set for the PATCH and PUT methods.

POST, PATCH, and PUT use the body as the write/overwrite.

When sending a POST request, you can send an array of objects to insert several Mongo Documents in one request.

The difference between PUT and PATCH, is that PUT will only update one document and insert a new document if it doesn't already exist. PATCH will update any document that meets the query criteria; therefore if you want to update only one document, but not insert if it already exists, than do a PATCH request with the _id field set.

A sample fetch request from the client would look like the following:

  fetch('https://mongo-broker.glitch.me/sampleDatabase/users', {
    headers: {
      'Content-Type': 'application/json',
      authorization: <authkey>
    },
    method: 'POST',
    body: JSON.stringify({
      fname: 'Tom',
      lname: 'Tommerson'
    })
  }).then(r => r.json()).then(console.log)

NOTE: You can setup a free cloud instance of MongoDB with Atlas.

Crafted by Patrick Trester

mongo-broker's People

Contributors

uraikus avatar

Watchers

James Cloos avatar  avatar

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.