Introduction of AWS DynamoDB!!

DynamoDB is a NoSQL document database service that is fully managed. Unlike traditional databases, NoSQL databases, are schema-less. Schema-less simply means that the database doesn’t contain a fixed (or rigid) data structure.

Advantages:- 

  • DynamoDB is found under the Database section on the AWS Management Console.
  • DynamoDB can handle more than 10 trillion requests per day.
  • DynamoDB is serverless as there are no servers to provision, patch, or manage.
  • DynamoDB supports key-value and document data models.
  • DynamoDB synchronously replicates data across three Availability Zones in an AWS Region.
  • DynamoDB supports GET/PUT operations using a primary key.

Fast and flexible NoSQL database service for any scale

Features:- 

  1. Performance at scale
  2. High Availability and Durability
  3. No servers to manage
  4. Enterprise-ready

DynamoDB is a NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. Its flexible data model and reliable performance make it a great fit for mobile, web, gaming, ad-tech, IoT, and many other applications.

Applications best suit:- 

  1. Serverless Web Apps
  2. Mobile app backend
  3. Microservices

Let us make hands dirty

  • Create a table
  • Add data to a table
  • Query data in a table
  • Cleanup or delete table

Go to Services and select DynamoDB service 

→ On the DynamoDB Console, click “Create table

→Enter UsersInfo as the Table name. 

→Enter Name in for the Partition key and ensure String is selected.

→For now, keep everything default and click on Create button.

Now the table is ready, Add data into it

→Click on “Create Item”.

 →Enter the value e.g your good name

 → Then click on + button then select ” Insert ” → then select datatype as String provides field name as “EmailId” enter value → Click on “Save” button.

Now data is ready you can add more records for your testimonials.

Query record in a table:-

 → Select the “Query” from drop-down

→ Where it says, Enter value in the row next to the name Partition key. i.e Mahesh, in this case, it may be different for you.

 →Click on “Start search” button.

→You should see your search results

Once everything is done cleanup resources, delete resources.

 → Click on the Delete table button.

 → Ensure Delete all CloudWatch alarms for this table is selected and click Delete.

If you want to create a backup check “Create a backup before deleting this table”.

FireStore now supports IN Queries & array-contains!!

Firestore with new in and array-contains-any queries.

This is the good news for cloud firestore developers, the pain point they are facing unable to use of ‘in’ operator.

Image result for firestore

Cloud FireStore is NoSQL database built for global apps.

Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web apps — at a global scale. Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform.

The importance of ‘in’ is like a pinch of salt in day to day life.

In Query:

With the in query, you can query a specific field for multiple values (up to 10) in a single query. You do this by passing a list containing all the values you want to search in, and Cloud Firestore will match any document whose field equals one of those values.

in queries are the best way to run simple OR queries in Cloud Firestore. For instance, if the database for your E-commerce app had a customer_orders collection and you wanted to find which orders had a “Ready to ship”, “Out for delivery” or “Completed” status, this is now something you can do with a single query, like so:

collection(“orders”)
.where(
“status”, 
“in”, 
[“Ready to ship”, “Out For Delivery”, “Completed”]
)

one more example:-

citiesRef.where('country', 'in', ['India', 'Japan','CostaRica']);

array-contains-any query:

Firestore launched another feature similar to the in query, the array-contains-any query. This feature allows you to perform array-contains queries against multiple values at the same time.

In your e-commerce site has plenty of products with an array of categories that every item belongs in, and you want to fire a query to fetch products with a category such as “Appliances” or “Electronics” then.

collection(“products”).where(
 “category”,
 “array-contains-any”,
 [“Appliances”,”Electronics”]
)

one more example: 

citiesRef.where('regions', 'array-contains-any',
['west_coast', 'east_coast']);

Note:- These queries are also supported in the Firebase console, which gives you the ability to try them out on your dataset before you start modifying your client code.

Remember:

  • As we mentioned earlier, you’re currently limited to a maximum of 10 different values in your queries.
  • You can have only one of these types of operations in a single query. You can combine these with most other query operations, however.

References:-

https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html

https://firebase.google.com/docs/firestore/query-data/queries