Skip to main content

Posts

Showing posts with the label MongoDB

CRUD in MongoDB & Spring Data

Now, since we have already been introduced to mongo and its server is setup. We shall now move on to performing basic CRUD operations. Lets take a use case example of ‘Company’ database that stores employee information.  We wish to store employee name, email address, age and multiple addresses. Traditionally in RDBMS we would create an Employee table and Address Table having foreign key reference to ‘employee id ‘ Incase of NoSQL, we will be creating Employee documnet which will have store employee information like name, email, age and an array of employes address. Following is a snippet of the schema defined { "name" : "", "email" : "", "age" : “”, "address" : [ ... ] } Thus to begin with, we will first define the entities. We have employee as an aggregate root entity that stores list of address having 1-M relatioship. Address Entity is represend as @Embeddable as it is embaded in another aggregate root entity. Employee is...

MongoDB Setup & Overview

“ MongoDB is an open source, document oriented NoSQL database where data is represented & stored in the form of BSON(binary JSON) ”  Following is a key value representation of data in JSON format and its corresponding BS ON.It adds some "extra" information to documents, like length of string and sub-objects. This makes traversal faster. // JSON file    { "hello" : "world" } // BSON file "\x16\x00\x00\x00\x02hello\x00 \x06\x00\x00\x00world\x00\x00"   \x16\x00\x00\x00 // total document size \x02 // 0x02 = type String hello\x00 // field name \x06\x00\x00\x00world\x00 // field value \x00 // 0x00 = type end of object   With the growing use of Social Media platforms, large chunks of unstructured data was created .Thus, a need to to persist this unstructured data in th...