Sobes.tech
Junior — Middle

Does MongoDB support sharding mechanism for data distribution?

sobes.tech AI

Answer from AI

In database systems, the primary key must have the following characteristics:

  • Uniqueness: Values of the primary key must be unique for each record in the table. This guarantees unambiguous identification of each row.

  • Cannot be NULL: The fields used as the primary key cannot contain NULL, as this would violate uniqueness and identification.

  • Stability: The primary key values should not change frequently, as this can cause data integrity and relationship issues.

  • Single column or composite key: The primary key can consist of one or multiple columns.

  • Indexing: Usually, the database automatically creates an index on the primary key for faster searches.

Example of creating a table with a primary key in SQL:

CREATE TABLE Users (
    id INT PRIMARY KEY,
    username VARCHAR(50),
    email VARCHAR(100)
);

Here, id is the primary key, unique and not NULL.