Monday, 2 December 2013

MongoDB Queries - 2

MongoDB Update() method

MongoDB's update() method is used to update document into a collection. The update() method update values in the existing document.


> db.democol.find().pretty()

Result:

{
        "_id" : ObjectId("52963c2a6f63f810a98b7a98"),
        "title" : "Learn mongo",
        "by" : "mani",
        "likes" : 100
}
{
        "_id" : ObjectId("52963ce96f63f810a98b7a99"),
        "by" : "subramanian",
        "comments" : [
                {
                        "user" : "Tiara",
                        "message" : "Worth to read"
                }
        ],
        "likes" : 20,
        "title" : "Basic SQL"
}

> db.democol.update({'title':'Basic SQL'},{$set:{'title':'Learn SQL'}})
> db.democol.find().pretty()

Result:

{
        "_id" : ObjectId("52963c2a6f63f810a98b7a98"),
        "title" : "Learn mongo",
        "by" : "mani",
        "likes" : 100
}
{
        "_id" : ObjectId("52963ce96f63f810a98b7a99"),
        "by" : "subramanian",
        "comments" : [
                {
                        "user" : "Tiara",
                        "message" : "Worth to read"
                }
        ],
        "likes" : 20,
        "title" : "Learn SQL"
}

By default mongodb will update only single document, to update multiple you need to set a paramter 'multi' to true.

>db.democol.update({'title':'Basic SQL'},{$set:{'title':'Learn SQL'}},{multi:true})



The remove() Method

MongoDB's remove() method is used to remove document from the collection. remove() method accepts two parameters. One is deletion criteria and second is justOne flag

deletion criteria : (Optional) deletion criteria according to documents will be removed.

justOne : (Optional) if set to true or 1, then remove only one document.

>db.mycol.find()

Result:

{ "_id" : ObjectId(5983548781331adf45ec5), "title":"MongoDB Overview"}
{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}
Following example will remove all the documents whose title is 'MongoDB Overview'

>db.mycol.remove({'title':'MongoDB Overview'})
>db.mycol.find()

Result:

{ "_id" : ObjectId(5983548781331adf45ec6), "title":"NoSQL Overview"}
{ "_id" : ObjectId(5983548781331adf45ec7), "title":"Tutorials Point Overview"}


Remove only one

If there are multiple records and you want to delete only first record, then set justOne parameter in remove() method

>db.COLLECTION_NAME.remove(DELETION_CRITERIA,1)



MongoDB Projection

In mongodb projection meaning is selecting only necessary data rather than selecting whole of the data of a document. If a document has 5 fields and you need to show only 3, then select only 3 fields from them.

The find() Method

MongoDB's find() method, explained in MongoDB Query Document accepts second optional parameter that is list of fields that you want to retrieve. In MongoDB when you execute find() method, then it displays all fields of a document. To limit this you need to set list of fields with value 1 or 0. 1 is used to show the filed while 0 is used to hide the field.

> db.democol.find({},{title:1,_id:0})

Result:

{ "title" : "Learn mongo" }
{ "title" : "Learn SQL" }

Sunday, 1 December 2013

MondoDB Queries

The find() Method

To query data from MongoDB collection, you need to use MongoDB's find() method.

> db.democol.find()

Result:

{ "_id" : ObjectId("52963c2a6f63f810a98b7a98"), "title" : "Learn mongo", "by" :
"mani", "likes" : 100 }
{ "_id" : ObjectId("52963ce96f63f810a98b7a99"), "title" : "Learn SQL", "by" : "s
ubramanian", "likes" : 20, "comments" : [  {  "user" : "Tiara",  "message" : "Wo
rth to read" } ] }


The pretty() Method

To display the results in a formatted way, you can use pretty() method.

> db.democol.find().pretty()

Result:

{
        "_id" : ObjectId("52963c2a6f63f810a98b7a98"),
        "title" : "Learn mongo",
        "by" : "mani",
        "likes" : 100
}
{
        "_id" : ObjectId("52963ce96f63f810a98b7a99"),
        "title" : "Learn SQL",
        "by" : "subramanian",
        "likes" : 20,
        "comments" : [
                {
                        "user" : "Tiara",
                        "message" : "Worth to read"
                }
        ]
}


AND in MongoDB

In the find() method if you pass multiple keys by separating them by ',' then MongoDB treats it AND condition. Basic syntax of AND is shown below:

> db.democol.find({by:"mani"}).pretty()

Result:

> db.democol.find({by:"mani"}).pretty()
{
        "_id" : ObjectId("52963c2a6f63f810a98b7a98"),
        "title" : "Learn mongo",
        "by" : "mani",
        "likes" : 100
}

> db.democol.find({by:"mani",title:"Learn mongo"}).pretty()

Result:

{
        "_id" : ObjectId("52963c2a6f63f810a98b7a98"),
        "title" : "Learn mongo",
        "by" : "mani",
        "likes" : 100
}


OR in MongoDB

To query documents based on the OR condition, you need to use $or keyword. Basic syntax of OR is shown below:

> db.democol.find({$or:[{by:"mani"},{title:"Learn SQL"}]}).pretty()

Result:

{
        "_id" : ObjectId("52963c2a6f63f810a98b7a98"),
        "title" : "Learn mongo",
        "by" : "mani",
        "likes" : 100
}
{
        "_id" : ObjectId("52963ce96f63f810a98b7a99"),
        "title" : "Learn SQL",
        "by" : "subramanian",
        "likes" : 20,
        "comments" : [
                {
                        "user" : "Tiara",
                        "message" : "Worth to read"
                }
        ]
}

Thursday, 28 November 2013

MongoDB Create and drop methods

Create Database:

If you want to create a database with name <mydb>, then use DATABASE statement would be as follows:

>use mydb
switched to db mydb


To check your currently selected database use the command db

>db
mydb


If you want to check your databases list, then use the command show dbs.

>show dbs
local     0.78125GB
mydb  0.23012GB
test      0.23012GB

Drop Database:

db.dropDatabase()

Create Collection:

Basic syntax of createCollection() command is as follows

db.createCollection(name, options)

In the command, name is name of collection to be created. Options is a document and used to specify configuration of collection

ParameterTypeDescription
NameStringName of the collection to be created
OptionsDocument(Optional) Specify options about memory size and indexing

Options parameter is optional, so you need to specify only name of the collection. Following is the list of options you can use:


FieldTypeDescription
cappedBoolean(Optional) If true, enables a capped collection. Capped collection is a collection fixed size collecction that automatically overwrites its oldest entries when it reaches its maximum size. If you specify true, you need to specify size parameter also.
autoIndexIDBoolean(Optional) If true, automatically create index on _id field.s Default value is false.
sizenumber(Optional) Specifies a maximum size in bytes for a capped collection. If If capped is true, then you need to specify this field also.
maxnumber(Optional) Specifies the maximum number of documents allowed in the capped collection.

While inserting the document, MongoDB first checks size field of capped collection, then it checks max field.

EXAMPLES:

Basic syntax of createCollection() method without options is as follows

>use test
switched to db test
>db.createCollection("mycollection")
{ "ok" : 1 }
>


You can check the created collection by using the command show collections

>show collections
mycollection
system.indexes


Following example shows the syntax of createCollection() method with few important options:

>db.createCollection("mycol", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } )
{ "ok" : 1 }
>


In mongodb you don't need to create collection. MongoDB creates collection automatically, when you insert some document.

>db.tutorialspoint.insert({"name" : "tutorialspoint"})
>show collections
mycol
mycollection
system.indexes
tutorialspoint
>


Drop Collection:

Basic syntax of drop() command is as follows

db.COLLECTION_NAME.drop()

Example:

>db.mycollection.drop()
true
>

MongoDB Environment

To start a mongodb, following are the commands:

Command used to start the mongod.exe is running for connections,

C:\Mongo\mongodb-win32-x86_64-2008plus-2.4.8\bin>mongod.exe --dbpath "c:\Mongo\data"

Command to run the mongodb,

C:\Mongo\mongodb-win32-x86_64-2008plus-2.4.8\bin>mongo.exe

MongoDB Introduction



  •  MongoDB is an open-source document database, and leading NoSQL database. MongoDB is written in      c++.
  • MongoDB is a cross-platform, document oriented database that provides, high performance, high  availability, and easy scalability. MongoDB works on concept of collection and document.
  • Below given table shows the relationship of RDBMS terminology with MongoDB



RDBMSMongoDB
DatabaseDatabase
TableCollection
Tuple/RowDocument
columnField
Table JoinEmbedded Documents
Primary KeyPrimary Key (Default key _id provided by mongodb itself)
Database Server and Client
Mysqld/Oraclemongod
mysql/sqlplusmongo


  • Any relational database has a typical schema design that shows number of tables and the relationship between these tables. While in MongoDB there is no concept of relationship


Advantages of MongoDB over RDBMS


  • Schema less : MongoDB is document database in which one collection holds different different documents. Number of fields, content and size of the document can be 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


Why should use MongoDB


  • Document Oriented Storage : Data is stored in the form of JSON style documents
  • Index on any attribute
  • Replication & High Availability
  • Auto-Sharding
  • Rich Queries
  • Fast In-Place Updates
  • Professional Support By MongoDB


Where should use MongoDB?


  • Big Data
  • Content Management and Delivery
  • Mobile and Social Infrastructure
  • User Data Management
  • Data Hub



Monday, 7 October 2013

InfoSphere DataStage


Integrate all types of data on distributed and mainframe platforms

IBM® InfoSphere® DataStage® integrates data across multiple systems using a high performance parallel framework, and it supports extended metadata management and enterprise connectivity. The scalable platform provides more flexible integration of all types of data, including big data at rest (Hadoop-based) or in motion (stream-based), on distributed and mainframe platforms.

InfoSphere DataStage provides these features and benefits:

·         Powerful, scalable ETL platform—supports the collection, integration and transformation of large volumes of data, with data structures ranging from simple to complex.
·         Support for big data and Hadoop—enables you to directly access big data on a distributed file system, and helps clients more efficiently leverage new data sources by providing JSON support and a new JDBC connector.

·         Near real-time data integration—as well as connectivity between data sources and applications.

·         Workload and business rules management—helps you optimize hardware utilization and prioritize mission-critical tasks.
·         Ease of use—helps improve speed, flexibility and effectiveness to build, deploy, update and manage your data integration infrastructure.

·         Rich support for DB2Z and DB2 for z/OS—including data load optimization for DB2Z and balanced optimization for DB2 on z/OS

Thursday, 3 October 2013

Diff b/w Rest and Soap

  • SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.
  • SOAP is a XML based messaging protocol and REST is not a protocol but an architectural style.
  • SOAP has a standard specification but there is none for REST.
  • Whole of the web works based on REST style architecture. Consider a shared resource repository and consumers access the resources.
  • Even SOAP based Web service can be implemented in RESTful style. REST is a concept that does not tie with any protocols.
  • SOAP is distributed computing style and REST is web style (web is also a distributed computing model).
  • REST messages should be self-contained and should help consumer in controlling the interaction between provider and consumer(example, links in message to decide the next course of action). But SOAP doesn’t has any such requirements.
  • REST does not enforces message format as XML or JSON or etc. But SOAP is XML based message protocol.
  • REST follows stateless model. SOAP has specifications for stateful implementation as well.
  • SOAP is strongly typed, has strict specification for every part of implementation. But REST gives the concept and less restrictive about the implementation.
  • Therefore REST based implementation is simple compared to SOAP and consumer understanding.
  • SOAP uses interfaces and named operations to expose business logic. REST uses (generally) URI and methods like (GET, PUT, POST, DELETE) to expose resources.
  • SOAP has a set of standard specifications. WS-Security is the specification for security in the implementation. It is a detailed standard providing rules for security in application implementation. Like this we have separate specifications for messaging, transactions, etc. Unlike SOAP, REST does not has dedicated concepts for each of these. REST predominantly relies on HTTPS.
  • Above all both SOAP and REST depends on design and implementation of the application.

Kiro - Core Features

What is Kiro Kiro is an innovative AI-powered IDE that revolutionizes software development through intelligent assistance and structured wor...