AMP for E-Commerce Part 2: Creating Backend with Alibaba Cloud ApsaraDB for MongoDB

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: In this three-part tutorial, we will explore how to create a fully functional e-commerce mobile application using AMP.

By Sai Sarath Chandra, Alibaba Cloud Tech Share Author and Alibaba Cloud MVP

This blog entry is a continuation of the articleAMP for E-Commerce Part 1. Before we start exploring Alibaba Cloud ApsaraDB for MongoDB, we will discuss why we chose this as the backend for the proof of concept (POC).

Relational vs. Non-Relational Databases

In general, there are two types of databases:

  • Relational databases
  • Non-relational databases

In relational databases, we need to know exactly what data we are going to manage. We need to model the database and then create the query corresponding to the data model and fetch accordingly. A typical example of a very popular relational databases is MySQL. MySQL has become an inexpensive option for so many organizations. Although relational databases are powerful, they do have certain limitations. Relational databases are unsuitable for processing high data volumes and is not good at addressing the needs of the changing data.

In the digital Era we see a fluid data where we don't know the exact representation of the data. The data model keeps changing for a particular entity, and that's how the NoSQL data model came into existence. One of such popular NoSQL databases MongoDB. NoSQL is quite a hot topic in the industry now. It is mainly suited for the small and medium level organizations where they want to start up their business but are not clear about what the data might be. NoSQL doesn't have any predefined schema. As a developer, you do not need to worry about having the expertise of a DBA to maintain a well performing backend if you opted for NoSQL.

Benefits of MongoDB

Now we will talk more about the MongoDB and the benefits of using the MongoDB over relational databases like MySQL.

Mongo DB Is Schemaless

In relational databases, we define the table schema before any other data operation. Whenever we insert some data into the table we need to make sure we adhere to the schema of the table. If you think there is a change in the model of the data then we need to change the entire table schema or we need to create a new table and normalize it. But in MongoDB the data is stored in JSON like structures.

In relational databases we have table which consists of rows of data; in MongoDB we have collection which consists the data as documents. A typical document would be nothing more than a JSON like structure. The interesting part in MongoDB is that multiple documents can consist multiple field with multiple data types. Initially, it may seem a little confusing to use MongoDB, but after getting used to it, you will enjoy the flexibility it offers.

MongoDB Is Reliable

We can all agree that relational databases available in the market are backed by years of research and proven industry adoption. However, we should also notice that the MongoDB is also adopted by big companies like T-mobile, Sony, Surveymonkey, Foursquare, Invision, and many others.

MongoDB Is Easy to Scale (Sharding and Replication)

Sharding refers to dividing your dataset up over multiple MongoDB servers. You pick a field to act as a division point in your dataset, referred to as a shard keys. Based on this shard key, data is distributed across multiple servers. Sharding allows for horizontal scaling, which is difficult to implement in MySQL.

There are two scenarios that might ultimately motivate you to shard MongoDB: your dataset has become truly massive and indexes cannot fit in memory any longer, or your application is write-heavy and you need to distribute writes over multiple servers

MongoDB supports built-in replication sharding and auto-elections. Using auto-elections, you can set up a secondary database to automatically take over if the primary database fails. MongoDB uses replica sets to create multiple copies of the data. Each member of the replica set can have the role of primary or secondary at any point in the process. Reads and writes are done on the primary replica by default and then replicated to the secondary replicas.

Replication and sharding makes mongo DB very easy to scale.

Deep Query-Ability, Security, and Developer Friendly

MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL. From the security perspective, MongoDB is more secure because traditional databases can suffer with the SQL injection attacks. For MongoDB, the likelihood of having injection attacks is much lower because of the variable data it stores in the name of its documents.

From the developer perspective, MongoDB is more developer friendly. It is well documented and well-written clients for most major languages. The main advantage with the mongo DB is that the JavaScript based query language that more suited to web developers. It makes prototyping applications much faster, shortening the time for releases and builds

Alibaba Cloud ApsaraDB for MongoDB

Alibaba Cloud ApsaraDB for MongoDB is a secure, reliable, and elastically scalable cloud database service. It currently supports the ReplicaSet and Sharding architectures and can be quickly deployed in just a few steps. The benefits of using Alibaba Cloud ApsaraDB for MongoDB include:

Reliable Storage

  • Built based on Alibaba Cloud Apsara distributed file system and SSD high-performance storage.
  • Three-node ReplicaSet architecture, ensuring redundant data storage.
  • Periodic automatic backup, ensuring reliable data storage.

Elastic Scaling

  • Supports both the ReplicaSet and Sharding architectures.
  • Nodes of the ReplicaSet and Sharding can be upgraded or downgraded as required to scale resources.
  • The number of mongoses and shards in Sharding instances can be scaled out at any time.

Professional Services

  • Senior Alibaba Cloud technical team members available to provide professional services to boost security and resource elasticity.
  • Optimized kernel for performance, security, and other dimensions managed by the source code team.

Cost-effective

  • Cost-effective with no upfront cost or long-term commitment.
  • Offers flexible payment options including Monthly Subscription and Pay-As-You-Go.

Details of ApsaraDB for MongoDB

Architecture

Alibaba Cloud ApsaraDB for MongoDB supports both ReplicaSet Architecture & Sharding Architecture. There will be minimum of three nodes operating in the replica set architecture by default, where one will be primary, another will be secondary and other will be the hidden. If the primary files the system will choose the secondary, for some reason if the secondary is not available then the system switches to the hidden database to make sure the service is available.

The fractional service (shard) and configuration service (configserver) adopt the stable and reliable three-node ReplicaSet architecture.

Security

Alibaba Cloud is well known for its security measures across all its products. ApsaraDB for MongoDB provides built-in backup mechanism and recovery which helps in preventing Data loss and minimising the cost of in proper operation it is also equipped with and Anti-DDoS and supports IP whitelist configuration which supports a maximum of 1000 whitelist rules and performs risk control from the access source.

Management

ApsaraDB for MongoDB also comes with visualized operations and management platform. You can monitor the instance information, such as youth CPU utilization connections, and obtain other information visually. The visualized IT management platform simplifies high-frequency and high-risk operations, such as instance restart. ApsaraDB for MongoDB makes data recovery into a single click operation. It also proactively performs subgrade for database kernel version management, and quickly repairs the defects, freeing you from daily version management.

E-Commerce Store Backend

Now we will create the actual setup for our e-commerce store backend and little bit of networking. We create an architecture something like this going further. Please find the diagram for reference

1

This is the recommended architecture from Alibaba Cloud for accessing the MongoDB instances.

First, we need to create an Alibaba Cloud ECS instance to reduce the complexity of going through the multiple Linux commands. We will create the Windows VM and access MongoDB from the ECS instance.

If you are connecting from the Internet then you need to use the following credentials

IP Address/Host Name: 47.74.237.40 or
Username : Administrator
Password :

2

If you have connected using the Remote Desktop protocol then you should be able to see the Windows connected.

Creating an ApsaraDB for MongoDB Service

Now we will create backend database of the ApsaraDB for MongoDB Service in Alibaba Cloud. On the console, navigate to Products > ApsaraDB for MongoDB.

You will be taken to this screen where I am creating the instance in the same location of the ECS Instance (Singapore). Click on create Instance. For this demo we are creating a "Replica Set Instance"

3

Once you click on the Create Instance Button You will be taken to the below screen. Don't panic if you didn't see the below screen. You will be by default taken to the Subscription (Replica Set). You need to change to the Pay-As-You-Go (Replica Set) model where you can see all the default values are populated. You need to select the VPC model of connection

4

You can see the VPCID and the VSwitchID are populated automatically along with the default configuration. If your configuration is missing the VPCID/VSwitch ID then your ECS Instance or the MongoDB instance is not at the same region. Provide a password and remember it future use for logging into database

5

Once you have done all the steps correctly you should have an active MongoDB service on Alibaba Cloud. You will see the following instance running under the "Singapore" region.

6

Once you click on the instance ID then you will be navigated to this screen where you will see the Intranet & Public IP connection protocols. Before accessing, we need to whitelist the IP address of the ECS instance by clicking at the "Set the whitelist and the address will be displayed".

7

Once you click, you will be navigated here. You have to click on the "Import ECS intranet IP" this will automatically detect the Intranet IP address of the ECS Instance

8

Then there you go the connection details for the Intranet will be displayed we will use this details for the Intranet connection. We will be using the connection String URI to connect. We will using the same in the next tutorial

9

Next Steps

We will create a simple Express based node API to query data for our database and serve the E-Commerce App built by leveraging the open source templates provided by the AMP Site. The whole integration will happen in the next tutorial, so please be sure to check it out.

目录
相关文章
|
JSON 弹性计算 NoSQL
AMP for E-Commerce Part 3: Integrating the Entire Application with Alibaba Cloud ApsaraDB for MongoDB
In this three-part tutorial, we will explore how to create a fully functional e-commerce mobile application using AMP.
1916 0
AMP for E-Commerce Part 3: Integrating the Entire Application with Alibaba Cloud ApsaraDB for MongoDB
|
4月前
|
NoSQL MongoDB 数据库
数据库数据恢复—MongoDB数据库数据恢复案例
MongoDB数据库数据恢复环境: 一台操作系统为Windows Server的虚拟机上部署MongoDB数据库。 MongoDB数据库故障: 工作人员在MongoDB服务仍然开启的情况下将MongoDB数据库文件拷贝到其他分区,数据复制完成后将MongoDB数据库原先所在的分区进行了格式化操作。 结果发现拷贝过去的数据无法使用。管理员又将数据拷贝回原始分区,MongoDB服务仍然无法使用,报错“Windows无法启动MongoDB服务(位于 本地计算机 上)错误1067:进程意外终止。”
|
4月前
|
缓存 NoSQL Linux
在CentOS 7系统中彻底移除MongoDB数据库的步骤
以上步骤完成后,MongoDB应该会从您的CentOS 7系统中被彻底移除。在执行上述操作前,请确保已经备份好所有重要数据以防丢失。这些步骤操作需要一些基本的Linux系统管理知识,若您对某一步骤不是非常清楚,请先进行必要的学习或咨询专业人士。在执行系统级操作时,推荐在实施前创建系统快照或备份,以便在出现问题时能够恢复到原先的状态。
413 79
|
4月前
|
存储 NoSQL MongoDB
MongoDB数据库详解-针对大型分布式项目采用的原因以及基础原理和发展-卓伊凡|贝贝|莉莉
MongoDB数据库详解-针对大型分布式项目采用的原因以及基础原理和发展-卓伊凡|贝贝|莉莉
269 8
MongoDB数据库详解-针对大型分布式项目采用的原因以及基础原理和发展-卓伊凡|贝贝|莉莉
|
3月前
|
运维 NoSQL 容灾
告别运维噩梦:手把手教你将自建 MongoDB 平滑迁移至云数据库
程序员为何逃离自建MongoDB?扩容困难、运维复杂、高可用性差成痛点。阿里云MongoDB提供分钟级扩容、自动诊断与高可用保障,助力企业高效运维、降本增效,实现数据库“无感运维”。
|
7月前
|
NoSQL MongoDB 数据库
数据库数据恢复——MongoDB数据库服务无法启动的数据恢复案例
MongoDB数据库数据恢复环境: 一台Windows Server操作系统虚拟机上部署MongoDB数据库。 MongoDB数据库故障: 管理员在未关闭MongoDB服务的情况下拷贝数据库文件。将MongoDB数据库文件拷贝到其他分区后,对MongoDB数据库所在原分区进行了格式化操作。格式化完成后将数据库文件拷回原分区,并重新启动MongoDB服务。发现服务无法启动并报错。
|
8月前
|
存储 NoSQL MongoDB
微服务——MongoDB常用命令1——数据库操作
本节介绍了 MongoDB 中数据库的选择、创建与删除操作。使用 `use 数据库名称` 可选择或创建数据库,若数据库不存在则自动创建。通过 `show dbs` 或 `show databases` 查看所有可访问的数据库,用 `db` 命令查看当前数据库。注意,集合仅在插入数据后才会真正创建。数据库命名需遵循 UTF-8 格式,避免特殊字符,长度不超过 64 字节,且部分名称如 `admin`、`local` 和 `config` 为系统保留。删除数据库可通过 `db.dropDatabase()` 实现,主要用于移除已持久化的数据库。
583 0
|
8月前
|
存储 NoSQL MongoDB
从 MongoDB 到 时序数据库 TDengine,沃太能源实现 18 倍写入性能提升
沃太能源是国内领先储能设备生产厂商,数十万储能终端遍布世界各地。此前使用 MongoDB 存储时序数据,但随着设备测点增加,MongoDB 在存储效率、写入性能、查询性能等方面暴露出短板。经过对比,沃太能源选择了专业时序数据库 TDengine,生产效能显著提升:整体上,数据压缩率超 10 倍、写入性能提升 18 倍,查询在特定场景上也实现了数倍的提升。同时减少了技术架构复杂度,实现了零代码数据接入。本文将对 TDengine 在沃太能源的应用情况进行详解。
405 0
|
9月前
|
存储 NoSQL MongoDB
数据库数据恢复—MongoDB数据库迁移过程中丢失文件的数据恢复案例
某单位一台MongoDB数据库由于业务需求进行了数据迁移,数据库迁移后提示:“Windows无法启动MongoDB服务(位于 本地计算机 上)错误1067:进程意外终止。”
|
11月前
|
存储 JSON NoSQL
学习 MongoDB:打开强大的数据库技术大门
MongoDB 是一个基于分布式文件存储的文档数据库,由 C++ 编写,旨在为 Web 应用提供可扩展的高性能数据存储解决方案。它与 MySQL 类似,但使用文档结构而非表结构。核心概念包括:数据库(Database)、集合(Collection)、文档(Document)和字段(Field)。MongoDB 使用 BSON 格式存储数据,支持多种数据类型,如字符串、整数、数组等,并通过二进制编码实现高效存储和传输。BSON 文档结构类似 JSON,但更紧凑,适合网络传输。
422 15

推荐镜像

更多
下一篇
oss云网关配置