Atlas as a service

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; concept pipeline



; 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());
};
      
      



GitHub.





API MiniAtlas

 β€” , . Realm Web SDK, REST; -.





, 6 :





API

















GET





/getClusters









POST





/getClusters









GET





/getClusterState?clusterName:cn









PATCH





/modifyCluster









POST





/pauseCluster









DELETE





/deleteCluster?clusterName:cn





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

, 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.





JQuery Realm.





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 .





, , , ! . , .






"NoSQL"





Β«MongoDB Map-Reduce FrameworkΒ»








All Articles