The translation of the material was prepared as part of the "NoSQL" course .
We also invite everyone to join the MongoDB Map-Reduce Framework two-day intensive course.
- Topics of the 1st day : CRUD-operations; filtering by fields;sort
,skip
,limit
; requests for subdocuments.
- Topics for 2 days : the concept of map-reduce; conceptpipeline
; structure and syntax of aggregation; stage$match
; stage$group
; stage$lookup
.
MongoDB . MongoDB . MongoDB Atlas, , .
Atlas . , , . β , API- Atlas MongoDB , MongoDB Atlas.
, , MongoDB. , , . , , . , Atlas, Atlas. .
API- Atlas , . :
;
API-, ;
API.
, , Twilio . .
, Realm.
API Atlas
API- Atlas Realm.
API Atlas ( getOneCluster
):
/*
* Gets information about the requested cluster. If clusterName is empty, all clusters will be fetched.
* See https://docs.atlas.mongodb.com/reference/api/clusters-get-one
*
*/
exports = async function(username, password, projectID, clusterName)
{
const arg = {
scheme: 'https',
host: 'cloud.mongodb.com',
path: 'api/atlas/v1.0/groups/' + projectID +'/clusters/' +
clusterName,
username: username,
password: password,
headers: {'Content-Type': ['application/json'],
'Accept-Encoding': ['bzip, deflate']},
digestAuth:true
};
// The response body is a BSON.Binary object. Parse it and return.
response = await context.http.get(arg);
return EJSON.parse(response.body.text());
};
API MiniAtlas
β , . Realm Web SDK, REST; -.
getClusters
(: Value Secret):
/*
* GET getClusters
*
* Query Parameters
*
* None
*
* Response - Currently all values documented at https://docs.atlas.mongodb.com/reference/api/clusters-get-all/
*
*/
exports = async function(payload, response) {
var results = [];
const username = context.values.get("username");
const password = context.values.get("apiKey");
projectID = context.values.get("projectID");
// Sending an empty clusterName will return all clusters.
var clusterName = '';
response = await context.functions.execute("getOneCluster", username, password,
projectID, clusterName);
results = response.results;
return results;
};
- GitHub.
- URL-, API:
API
exports = function(payload) {
const headers = context.request.requestHeaders
const { Authorization } = headers
const user_id = Authorization.toString().replace(/^Bearer/, '')
return user_id
};
MongoDB Realm , , / , API, OAuth 2.0 Facebook, Google Apple ID.
Google OAuth β , , .
. , , , API.
MongoDB Stitch Browser SDK Google ( ) Google StitchAppClient.
let credential = new stitch.GoogleRedirectCredential();
client.auth.loginWithRedirect(credential);
, API , StitchAppClient
:
let userId = client.auth.authInfo.userId;
API. API createCluster
:
export const createCluster = (uid, data) => {
let url = `${baseURL}/createCluster`
const params = {
method: "post",
headers: {
"Content-Type": "application/json;charset=utf-8",
...(uid && { Authorization: uid })
},
...(data && { body: JSON.stringify(data) })
}
return fetch(url, params)
.then(handleErrors)
.then(response => response.json())
.catch(error => console.log(error) );
};
API webhooks.js.
Postman. API .
, , , ! . , .
Β«MongoDB Map-Reduce FrameworkΒ»