Monday, 31 December 2018

MongoDB with Python - Basics III - Find/Select Operation


Hoping you guys are enjoying the NoSql journey so far (previous posts links), till now we have seen basic CRUD operation. From this post onward, I am diving in details of these operations and starting with FIND or SELECT operation in MongoDB. We will learn what are the ways and options provided by MongoDB to select or project the data.

When you start working with complex queries you might {as I have said "Might"} face difficulties with tracking of braces {([ as I've experienced the same with me/my team/students and colleagues. But no worries, Jupyter Notebook provides a  couple highlighter for braces when selected or you can use notepad++ also (which I think is not so useful as you are not gonna copy/paste the syntax so frequently).

I advise everyone to avoid the writing queries directly on mongo shell prompt as it doesn't provide any intelligence and not so good in fixing queries if made mistake.

I am sure you will love this post as well and if have any question feel free to ask in comment section below.

For on Mongo DB -> Link


There are many more Find/Read Operators supported by MongoDB, Full list can be found HERE

CRUD Operation - (Read) : Link




Next Post on this Series and more on MongoDB can be find here -> LINK




Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Saturday, 29 December 2018

MongoDB with Python - Basics II - CRUD Operations


In this post, we will learn about the Advance Find and Create Operations with Sort, Skip and Limit functionality. Pymongo driver support almost same kind of syntax for python which mongo shell used.
The benefit of python (or any programming language) + mongo is to use both langauge/db functionality to work with mongo. Though, to perform the same operation is faster then performing by python but it depends on the activity you are performing.



CRUD Operation - (Create, Read, Update & Delete) : Link




Next Post on this Series and more on MongoDB can be find here -> LINK




Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Friday, 28 December 2018

MongoDB with Python - Basics I - CRUD Operations


In Previous few posts (Link), We have learnt about MongoDB Cloud Setup, Installation and Basic commands to do CRUD operation with MongoDB. It can be accessed by programming language such as python, java, and node.js by using respective native drivers. We will start with PyMongo (python driver) to access mongo from python.



CRUD Operation - (Create, Read, Update & Delete) : Link




Next Post on this Series and more on MongoDB can be find here -> LINK





Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Tuesday, 25 December 2018

MongoDB Atlas - Off Premise Way (DBaaS)


MongoDb also provide cloud services (Database as a Service - DaaS), called MongoDB Atlas, to host your mongo database on cloud. Let's see how we can setup an cloud account and access the MDB from local machine.

Cluster Step :
1. Create an account on https://cloud.mongodb.com
2. Once you are in, the very first thing which it asked to choose your cluster configuration.
2a. It gives you to choose one of cloud service which are - AWS, Google, Azure, Choose whatever you like
2b. But always choose "FREE TIER CLUSTER" (M0 Instance) else there will be usage charge.
3. Once you have selected appropriate config, it will start building your mongoDB Cluster, it will take few mins to complete the setup.
4. When done, it will be like this, usually use Cluster0 as name, you can modify it though -




How to access from local system :

You need to install Mongo Shell to access cloud db which comes with Mongo DB pkg. You can download and install on your OS (Windows/Linux) from here - https://www.mongodb.com/download-center/enterprise

1. Login on https://cloud.mongodb.com and click on Clusters in left hand side list.
2. Click on Connect and follow below steps -
3a. Whitelist your id so that you can connect with your system or any ip address. Click on "Add a different IP Address" and to allow to connect from any system, Use 0.0.0.0 as IP address
3b. Create your cluster credential


4. Once done, you will see the below screen
5a. Now, Click on Choose connection method and click on "Connect with Mongo Shell" -


5b. Now, click on standard connection string


6. Copy the string and replace the <PASSWORD> with the password which you created in Cluster Setup Step #4.
7. Now, As I have installed the MongoDB Shell in Step #1, we need to add MongoDB Bin directory path into system path. You can add this path into windows env variable or Linux user profile so that you can access mongo command from any location.
8. Once path has been added, open cmd or terminal and paste the connection string which you copied and modified in step #5


9. When connected successfully, you can try to run commands as below -


10. For more commands, you can visit this link - https://www.datagenx.net/2018/12/learn-mongo-db-basics.html

11. Mongo Atlas Cloud Step has been completed and verified successfully. You can connect with the same connection string from any system (if firewall allows and have mongo shell installed)

Let me know in comments if you face any issue while doing Atlas setup.
Next Post on this Series and more on MongoDB can be find here -> LINK




Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


MongoDB - Embedding v/s Referencing


MongoDb, a NoSQL document DB, doesn't support the JOIN as RDBMS do which is a very useful feature in DB domain. So what's new or addition in MongoDb which can overcome the JOIN feature. Let's understand this.

First of all, MongoDb is NOT a replacement of standard RDBMS system. It is misconception in DB world that NoSQL DB system will/can replace RDBMS or vice versa. No, It isn't or going to be. Both Database systems have own pros and cons which we will see later.



Embedding:
As the name itself reveals, Embed the data into the document means put all the data together in one document. This will provide a better read performance when you want to get all the related data in one read call as MongoDb stores one document at one place on the disk so minimum seek time is required when reading the data from disk drive.

Let's suppose. we want to create a data model for below ask -
==

So, Embedding document will look like -
==


Referencing:
Embedding will cause performance slowness when there are frequent CRUD operations on embedded document. In embedding, data duplication is highly probable. In these cases, we create a document reference rather than document. This is similar to parent-child relationship as we have in RDBMS.

Let's see now how our collection Books will look like -
==

Next Post on this Series and more on MongoDB can be find here -> LINK





Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Friday, 21 December 2018

Learn Mongo DB - Basics #1


While going through old pages, saw these mongoDB posts, so thought of continuing, We have already completed Installation of MongoDB, Now starting off with few basic commands which will help you to play around MongoDB :-)
==
Next Post on this Series and more on MongoDB can be find here -> LINK




Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Sunday, 25 November 2018

Let's Learn - Git Branching #2


Continuing from the last post Let's Learn - Git Branching #1 where we have learned about git branches, how to create and do the parallel development with them.

a. Merge the changes to master:  we have completed development with branch "atul" and ready to merge those changes/module with the main branch "master". If there are no changes have been done in master after creating "atul" branch, merging process is quite easy. We will look into this first -

i. Git log of "atul" branch: 
==

From the screenshot, we can see that "atul" branch has initiated from "master" branch from below commit point -
master -  de70bc2450802c80dc5520afa20b53de30488e5a
atul -  781d0bb325d67ba251e9db3af4d8ef90c246e406

ii. Git log of "master" branch: Let''s quickly check the master log as well


In master branch, last commit where the HEAD is pointing to "de70bc2450802c80dc5520afa20b53de30488e5a" same commit which we can see inside "atul" branch which tells us that there is no changes have been done in master after branching "atul" out.

This kind of merge is simple, as this is just a repoing of HEAD and done. Let's see how we can merge -
==

This command will merge the "atul" branch changes to "master", we can confirm the same from master git log.


Let's quickly make a new change in the master branch and check the git log







after committing the changes (third.txt) to master, git log shows that HEAD point to the latest change






Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Thursday, 22 November 2018

Let's Learn - Git Branching #1


Git branching feature is the most notable feature provided by Git for parallel development without impacting other developers. Using git branches, Developers can work on different module parallel with same base code and merge them later into one to build the complete picture.

We will start with the simple branching scenarios, where 2 branch has been initiated with same base code and merge them into one after few modifications.

a. List Git Branch:
==

b. Create Git Branch:
==

By above command, you can create a branch which has the same base code as master and when you list the branch, now you can see 2 names - atul (branch we created) and master (original). Asterisk * sign will tell us which repo is currently active.


c. Switch to Git Branch (checkout branch): 
===
To checkout branch is very easy and can be done by above command quickly. Just remember that whatever changes you have done in this branch will be local (remain) in this branch only.

d. Let's make some changes in the branch:
To make some changes, what I have done is created a new file name "atul.txt" and committed to this branch named "atul". You can found all the commands as below -
= =

now, we have made the changes, let's check the git log for this branch -


Here we have to understand one important branching concept, as you can see there are 2 branches (master and atul) pointer.

origin/master, master - this pointer will tell this branch "atul" has been branched from "master" from this commit de70bc2450802c80dc5520afa20b53de30488e5a

HEAD -> atul, origin/atul - this pointer will tell you that HEAD is pointing to "atul" branch means you are inside "atul" branch and commit 0ba89ab2d62a74c48951ba20b2c0f369c9a675a3 has been done

Let's quickly move to master branch and check whether these changes are there or not ??

e. Moving back to master:
Moving back process is the same as moving into the branch and check the git log in "master" branch


Here you can see that changes which we have committed inside "atul" branch hasn't been reflected in "master" branch.

This is how Git support Parallel Development with branching where the developer can create their own branch and develop the different features parallel.

f. What's the differences: 
We have created 2 branches named: "master" & "atul" and made some additional changes inside "atul" branch and commit to it. We can check the difference between these 2 branches by executing below command :
==

We will discuss about how to interpret this diff report in the next post, till then.....Happy Learning........





Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Thursday, 15 November 2018

Let's Learn - Lifecycle of Status of Git Files


In previous post, we have started with the account creation, Basics Git Commands ( Git Basics #1 and Git Basics #2) and Setup of password less Git push (https://buff.ly/2DBrQPl), Continuing the same here with adding a new Git post in Let's Learn series where we will learn about different file status while making the changes into git repository.


©git-scm.com

There are 4 type of status of files under git repository.

Untracked:  New Files under git repo about which git don't aware of.

Unmodified: File has been pulled from remote repo to local and not has any modification
* when you pull any git repository to your local, all files are tracked and unmodified.

Modified: Files which have been changed from last pull

Staged: Files which have been modified from last commit and staged (git add command) for commit to remote repo.






Like the below page to get update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Wednesday, 14 November 2018

Let's Learn - Password-less setup for Git


Every time when committing changes to github repository, we need to provide github credential which is annoying. Github provides solution for this repeatable activity by setting up password-less communication between github repo and local repository via SSH keys.


1. Generate SSH Keys -
ssh-keygen -t rsa -C your_registered_email@example.com



2, View and Copy the public key



3. Add the public keys to github repository.
a. Open your repo --> Setting



b. Click on Deploy --> Add Keys


c. Paste copied public key and save


SSH Setup has been completed, Now test it by pushing some changes to repository.

4. Making changes to README.md file


5. Stage and Commit


6. Last, push changes to remote.


Changes have been pushed to Remote repository without asking user credentials. You can use the same public key to all your git repository.

Hope you have enjoyed the post, will meet again with new stuff.....till then.......Happy Learning !!!..................



Like the below page to get update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group     


Tuesday, 13 November 2018

Let's Learn - Git Basics #2


Continuing from last post Let's Learn - Git Basics #1 where we have created the github account and a new repository. It is always a good practice to put all your code/work in one place so create a folder named something easily recognizable such as "gitCode" (in my case I have used "Git"). This will ensure that all your git code will be there for easy access.

Configuration:
Before starting to work, we will add configuration settings on our "Git" folder by executing below commands.


Check Configuration:
After setting up, you can view what your configurations look like by below commands -
=

=
=

Command to check Status:
To check the status of our work, GIT provides a command as below, It's very helpful while working with git - 
=
=
Working with new Repository:
a. We have already created a new repository on github named "git-learn", let's create a local repo as well.
==


b. After creating a local repository, we need to make it git repository by command "git init", this will create a hidden folder inside "git-learn" which holds all the changes done in local repository
=
==

c. Out git repository is ready, now let's make the first change inside it by creating a README.md file which holds the information about this repository. This is a markdown file which is used for repository documentation
==

d. After making this change, let's check the local git repo status.
==

"git status" command will display the current status of repo, Here, we can see README.md file under untracked files category (we will discuss about different type of status type later).
Untracked Files: Files about which git is not aware, as this is a new file. To push this file to remote git, we need to stage this file.

e. For staging this file, run the command as below -
==

After staging the file, we check the repo status which tells that there is a new file which has been staged to commit. But this changes hasn't been committed for push to remote repo.

f. Committing the changes is very easy and it's advisable to provide a proper comment while commit which help you in future while reviewing all the commits done on remote repo
==

g. Changes are committed, now we are good to push these changes to remote repository. But before that, as this is a new local repository, we need to tell this to which remote git repository it should commit to, Hence run the below add command, you have to run this command once per repository, so from next commit, no need to run this command unless you want to change the remote repo url.

When you push the local changes to remote, it will ask your github credentials as below (push will ask github credential every time which can be annoying and can be avoidable by setting up ssh keys with github account)
==

h. After entering github credentials, it will start pushing the data to remote git repo. 


i. When push is complete, we can check the current repo status as above.
j. You can view all the commits have been done on repository by "git log" command
==


In next post, we will see the type of changes done in git repository and how to setup password-less git repository.
Till then, Keep Loving this Blog .......... Happy Learning...........



Like the below page to get update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group