Chapter 3. Programming Language Drivers

In this chapter, we will cover the following recipes:

  • Installing PyMongo
  • Executing query and insert operations using PyMongo
  • Executing update and delete operations using PyMongo
  • Aggregation in Mongo using PyMongo
  • MapReduce in Mongo using PyMongo
  • Executing query and insert operations using a Java client
  • Executing update and delete operations using a Java client
  • Aggregation in Mongo using a Java client
  • MapReduce in Mongo using a Java client

Introduction

What we have seen so far using MongoDB is that we execute the majority of operations from the shell. The Mongo shell is a great tool for administrators to perform administrative tasks and for developers who would like to quickly test things by querying the data before coding the logic in the application. However, how do we write application code that will allow us to query, insert, update, and delete (among other things) the data in MongoDB? There has to be a library for the programming language in which we write our application.

We should be able to instantiate something or invoke methods from the program to perform some operations on the remote Mongo process. How will this happen unless there is a bridge that understands the protocol of communication with the remote server and is able to transmit the operation to execute over the wire we require on the MongoDB server process and get the result back to the client? This bridge, simply put, is called the driver, which is also referred to as a client library. Drivers form the backbone of Mongo's programming language interface. In the absence of drivers, it would have been the responsibility of the application to communicate with the MongoDB server using a protocol that the server understands. This would have been a lot of work not only to develop but also to test and maintain. Though the communication protocol is standard, there cannot be one implementation that works for all languages. A variety of programming languages need to have their own implementations that expose, more or less, the same sort of programming interface to all languages. The core concepts of client APIs that we will see in the chapter holds good for all languages.

Note

Mongo has support for all the major programming languages and is supported by MongoDB, Inc. There is even a huge array of programming languages supported by the community. You might take a look at the various platforms supported by Mongo by visiting http://docs.mongodb.org/ecosystem/drivers/community-supported-drivers/.

To know more about the underlying protocol used by MongoDB or about communication between the client and the server, and to see what goes over the wire, refer to my blog at http://amolnayak.blogspot.in/2014/09/mongodb-wire-protocol-analysis_14.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset