Thursday, 28 December 2017

Errors !!!

MongoDB : Errors !!!

When a create command is triggered with no parameters, then a generic error will be thrown:

Example

Command :  db.createCollection();

                    this command expects two parameters: 1. name of the collection and 2. Properties for the collection. Collection name is a compulsory here. if collection name is not provided, then the below error is thrown :

 
   



Friday, 11 August 2017

FAQs

1. How to list all the collection names ?.
A:  db.getCollectionNames();
2. How to clear the cmd prompt ?.
A: cls
3. How to get list of database names?.
A: db.adminCommand({ listDatabases : 1});
4. How to know the currently using database ?.
A: db
5. How to print Collection in JSON format in Mongoshell ?.
A: db.collectionName.find().limit(<no of collections>).pretty();
6. How to replace or rename a key in collection.
A: db.collectionName.update({},{$replace:{'old value':'new value'}});

Monday, 24 July 2017

Creation of Database and collection

the command to create a database is :

use <databasename>

note : Make sure that database name should not contain special characters because it effects the deployments of mongodb in various environments.

Creation of Collection :

Collection : it s a BSON Document (JSON like format).
simply its a collection of key value pairs.

For naming conventions : _ is used before the collection name.
while creating a collection there are certain parameters that's need to be passed, though they are optional , lets have a quick round of introduction to parameters.

Example : db.createCollection(<name of collection>, {
                                                                                       capped : <boolean>,
                                                                                        autoIndexId : <boolean>,
                                                                                        size: <number>,
                                                                                        max:<number>,
                                                                                        storageEngine:<document>,
                                                                                        validator: <document>,
                                                                                           validationLevel: <string>,
                                                                                          validationAction: <string>});


Introduction to Client and server ports.

1. Run Mongod : Server local port will always be 27017.
2. Run Mongo : Client local port  will always be 127.0.0.1:5108
                                  5108 may change.

once mongo connects to mongod, there will be a log displayed.

1. Clients port with time stamp.
2. Application name.
3. Driver name.
4. Version.
5. OS type, OS name, architecture, Version.

On Client Side :

if access control is not enabled then an error log is displayed as :

"Access control is not enabled for the database"
Also:
"Read, Write, Permission is logged: Read and Write access to data and configuration is unrestricted"


Tuesday, 18 July 2017

Mongodb -- Database -- Naming Conventions.

Database Naming Conventions:



The naming for database is case insensitive. Since you can use any letter, any special character for creating a database. But for deployments of MongoDB on certain platforms, there are some restrictions.

Windows :

Do not use following characters in naming a database name for MongoDB deployment  on windows.

/\. "$*<>:|?

also there should be no "NULL" characters in database names.

Monday, 3 July 2017

CRUD Operations.

CRUD Operations :

MongoDB has the following CRUD Operations.

1. Create Operation.
2. Read Operation.
3. Update Operation.
4. Delete Operation.

CREATE OPERATION :

Create or Insert operation inserts or create a document into collection. If there is no collection exists, then it will create a collection and insert the document.

Inserting of documents will be done with the following ways :

1. db.collection_name.insert({});
2. db.collection_name.insertOne({});
3. db.collection_name.insertMany({});

I. insert operations target a single collection. Write operations in the MongoDB are "atomic".

Atomicity and Transaction :

Write operation on a document is always functions individually, whether it is a part of multi documents -- collection or a single document -- collection.

$isolate -- operator is used to perform "write" operation that effects multiple documents.

When a $isolate operator is performed on multiple documents, it will not effect the other processes.