0% found this document useful (0 votes)
86 views

Mongodb Schema Validation

This document discusses MongoDB schema validation. MongoDB is a popular open-source document-oriented NoSQL database that stores data in BSON format like JSON. The document describes how to create a "posts" collection in MongoDB and configure a JSON schema validator to validate documents inserted into the collection. The schema defines the required "title" and "body" fields as strings and optional "category", "likes", "tags", and "date" fields with specific data types. This ensures only valid documents matching the defined schema can be inserted into the "posts" collection.

Uploaded by

SABARIMANI PUVI
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Mongodb Schema Validation

This document discusses MongoDB schema validation. MongoDB is a popular open-source document-oriented NoSQL database that stores data in BSON format like JSON. The document describes how to create a "posts" collection in MongoDB and configure a JSON schema validator to validate documents inserted into the collection. The schema defines the required "title" and "body" fields as strings and optional "category", "likes", "tags", and "date" fields with specific data types. This ensures only valid documents matching the defined schema can be inserted into the "posts" collection.

Uploaded by

SABARIMANI PUVI
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CENTRE FOR CAREER DEVELOPMENT

Application Oriented Project Report


Of
Skill Development Training Programme (SDT)

Tech name

Mongodb Schema Validation


Submitted by
Agnes Metilda.R,(710119205001)
Akash.J, (710119205002)
Akash.M(710119205003)
V SEMESTER BE-IT Students (Batch: 2019-2023)

Department of Information Technology

Adithya Institute of Technology, Coimbatore

Department of Information Technology

BONAFIDE CERTIFICATE

Certified that this project report “mongodb Schema Validation” are the
bonafide work of “Agnes Metilda.R, Akash.J,Akash.M ,” who carried out the
projects work under my supervision.
SIGNATURE SIGNATURE

Kalaivani T., Dr.S.M.Nandhagopal, Ph.D,

Assistant Professor, Professor & Head,

Department of CSE, Department of CSE&IT,

Adithya Institute of Technology, Adithya Institute of


Technology,

Coimbatore Coimbatore
Introduction:

MongoDB, the most popular NoSQL database, is an open-source document-oriented database.


The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB isn’t based on the table-like
relational database structure but provides an altogether different mechanism for storage and
retrieval of data. This format of storage is called BSON ( similar to JSON format). 

SQL databases store data in tabular format. This data is stored in a predefined data model which is
not very much flexible for today’s real-world highly growing applications.  Modern applications are
more networked, social and interactive than ever. Applications are storing more and more data
and are accessing it at higher rates.
Relational Database Management System(RDBMS) is not the correct choice when it comes to
handling big data by the virtue of their design since they are not horizontally scalable . If the
database runs on a single server, then it will reach a scaling limit. NoSQL databases are more
scalable and provide superior performance. MongoDB is such a NoSQL database that scales by
adding more and more servers and increases productivity with its flexible document model.

Features of MongoDB:

 Document Oriented: MongoDB stores the main subject in the minimal number of
documents and not by breaking it up into multiple relational structures like RDBMS. For
example, it stores all the information of a computer in a single document called Computer
and not in distinct relational structures like CPU, RAM, Hard disk, etc.
 Indexing: Without indexing, a database would have to scan every document of a collection
to select those that match the query which would be inefficient. So, for efficient searching
Indexing is a must and MongoDB uses it to process huge volumes of data in very less time.
 Scalability: MongoDB scales horizontally using sharding (partitioning data across various
servers). Data is partitioned into data chunks using the shard key, and these data chunks
are evenly distributed across shards that reside across many physical servers. Also, new
machines can be added to a running database.
 Replication and High Availability: MongoDB increases the data availability with multiple
copies of data on different servers. By providing redundancy, it protects the database from
hardware failures. If one server goes down, the data can be retrieved easily from other
active servers which also had the data stored on them.
 Aggregation: Aggregation operations process data records and return the computed
results. It is similar to the GROUPBY clause in SQL. A few aggregation expressions are
sum, avg, min, max, etc

Where do we use MongoDB?

MongoDB is preferred over RDBMS in the following scenarios:


 Big Data: If you have huge amount of data to be stored in tables, think of MongoDB before
RDBMS databases. MongoDB has built-in solution for partitioning and sharding your
database.
 Unstable Schema: Adding a new column in RDBMS is hard whereas MongoDB is schema-
less. Adding a new field does not effect old documents and will be very easy.
 Distributed data Since multiple copies of data are stored across different servers, recovery
of data is instant and safe even if there is a hardware failure.

Language Support by MongoDB :

MongoDB currently provides official driver support for all popular programming languages like
C, C++, Rust, C#, Java, Node.js, Perl, PHP, Python, Ruby, Scala, Go, and Erlang

Installing MongoDB :

Just go to http://www.mongodb.org/downloads  and select your operating system out


of Windows, Linux, Mac OS X and Solaris. A detailed explanation about the installation of
MongoDB is given on their site.
For Windows, a few options for the 64-bit operating systems drops down. When you’re running
on Windows 7, 8 or newer versions, select Windows 64-bit 2008 R2+. When you’re using
Windows XP or Vista then select Windows 64-bit 2008 R2+ legacy.

Advantages of MongoDB over RDBMS


 Schema less: MongoDB is a document database in
which one collection holds different documents.
Number of fields, content and size of the document
can differ from one document to another.

 Structure of a single object is clear.

 No complex joins.

 Deep query-ability. MongoDB supports dynamic


queries on documents using a document-based query
language that's nearly as powerful as SQL.

 Tuning.

 Ease of scale-out: MongoDB is easy to scale.

 Conversion/mapping of application objects to database objects not


needed.

 Uses internal memory for storing the (windowed)


working set, enabling faster access of data.

Schema Validation
db.createCollection("posts", {

validator: {

$jsonSchema: {

bsonType: "object",

required: [ "title", "body" ],

properties: {

title: {

bsonType: "string",

description: "Title of post - Required."

},

body: {

bsonType: "string",

description: "Body of post - Required."

},

category: {

bsonType: "string",

description: "Category of post - Optional."

},

likes: {

bsonType: "int",

description: "Post like count. Must be an integer - Optional."

},

tags: {

bsonType: ["string"],

description: "Must be an array of strings - Optional."

},

date: {

bsonType: "date",

description: "Must be a date - Optional."

}
}

})

You might also like