Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (5 votes)
19 views

Instant Access to MongoDB for Java developers design build and deliver efficient Java applications using the most advanced NoSQL database Francesco ebook Full Chapters

Java

Uploaded by

kunzniccol62
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
19 views

Instant Access to MongoDB for Java developers design build and deliver efficient Java applications using the most advanced NoSQL database Francesco ebook Full Chapters

Java

Uploaded by

kunzniccol62
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Download Full ebookname - Read Now at ebookname.

com

MongoDB for Java developers design build and


deliver efficient Java applications using the most
advanced NoSQL database Francesco

https://ebookname.com/product/mongodb-for-java-developers-
design-build-and-deliver-efficient-java-applications-using-
the-most-advanced-nosql-database-francesco/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Oracle Database Programming using Java and Web Services


1st Edition Kuassi Mensah

https://ebookname.com/product/oracle-database-programming-using-java-
and-web-services-1st-edition-kuassi-mensah/

ebookname.com

Learn Objective C for Java Developers 1st Edition James


Bucanek

https://ebookname.com/product/learn-objective-c-for-java-
developers-1st-edition-james-bucanek/

ebookname.com

Professional Eclipse 3 for Java Developers 1st Edition


Berthold Daum

https://ebookname.com/product/professional-eclipse-3-for-java-
developers-1st-edition-berthold-daum/

ebookname.com

Psychoanalysis and the Love of Arabic Hall of Mirrors 1st


Edition Nadia Bou Ali

https://ebookname.com/product/psychoanalysis-and-the-love-of-arabic-
hall-of-mirrors-1st-edition-nadia-bou-ali/

ebookname.com
The Flexible Phenotype A Body Centred Integration of
Ecology Physiology and Behaviour 1st Edition Theunis
Piersma
https://ebookname.com/product/the-flexible-phenotype-a-body-centred-
integration-of-ecology-physiology-and-behaviour-1st-edition-theunis-
piersma/
ebookname.com

Key Nursing Skills 1st Edition Barbara Workman

https://ebookname.com/product/key-nursing-skills-1st-edition-barbara-
workman/

ebookname.com

Better Than Vegan 101 Favorite Low Fat Plant Based Recipes
That Helped Me Lose Over 200 Pounds 1st Edition Del Sroufe

https://ebookname.com/product/better-than-vegan-101-favorite-low-fat-
plant-based-recipes-that-helped-me-lose-over-200-pounds-1st-edition-
del-sroufe/
ebookname.com

Materials and Infrastructures 2 1st Edition Toree

https://ebookname.com/product/materials-and-infrastructures-2-1st-
edition-toree/

ebookname.com

Statistical Reinforcement Learning Modern Machine Learning


Approaches 1st Edition Masashi Sugiyama

https://ebookname.com/product/statistical-reinforcement-learning-
modern-machine-learning-approaches-1st-edition-masashi-sugiyama/

ebookname.com
Uncovering the Hidden The Works and Life of Der Nister
Gennady Estraikh

https://ebookname.com/product/uncovering-the-hidden-the-works-and-
life-of-der-nister-gennady-estraikh/

ebookname.com
MongoDB for Java Developers

Design, build, and deliver efficient Java applications


using the most advanced NoSQL database

Francesco Marchioni

BIRMINGHAM - MUMBAI
MongoDB for Java Developers

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: August 2015

Production reference: 1070815

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78528-027-6

www.packtpub.com
Credits

Author Project Coordinator


Francesco Marchioni Shweta Birwatkar

Reviewers Proofreader
Daniel Mühlbachler Safis Editing
Weiwei Sun
Mehdi Tazi Indexer
Tejal Soni

Commissioning Editor
Veena Pagare Production Coordinator
Aparna Bhagat

Acquisition Editors
James Jones Cover Work
Aparna Bhagat
Nadeem N. Bagban

Content Development Editor


Neeshma Ramakrishnan

Technical Editor
Bharat Patil

Copy Editors
Merilyn Pereira
Laxmi Subramanian
About the Author

Francesco Marchioni is a Red Hat Certified JBoss Administrator (RHCJA)


and a Sun Certified enterprise architect working as a freelancer in Rome, Italy.
He started learning Java in 1997, and since then, he has followed the path to the
newest application program interfaces released by Sun. In 2000, he joined the
JBoss community, when the application server was running the release 2.X.

He has spent many years as a software consultant, wherein he envisioned many


successful software migrations from vendor platforms to open source products
such as JBoss AS, fulfilling the tight budget requirements of current times.

Over the past 5 years, he has been authoring technical articles for OReilly Media and
running an IT portal focused on JBoss products (http://www.mastertheboss.com).

In December 2009, he published JBoss AS 5 Development, which describes how to


create and deploy Java Enterprise applications on JBoss AS (http://www.packtpub.
com/jboss-as-5-development/book).

In December 2010, he published his second title, JBoss AS 5 Performance Tuning,


which describes how to deliver fast and efficient applications on JBoss AS
(http://www.packtpub.com/jboss-5-performance-tuning/book).

In December 2011, he published yet another title, JBoss AS 7 Configuration, Deployment,


and Administration, which covers all the aspects of the newest application server
release (http://www.packtpub.com/jboss-as-7-configuration-deployment-
administration/book).

In June 2013, he authored a new title, JBoss AS 7 Development, which focuses on


developing Java EE 6 API applications on JBoss AS 7 (https://www.packtpub.com/
application-development/jboss-7-development).
About the Reviewers

Daniel Mühlbachler got interested in computer science shortly after entering


high school, where he later developed web applications as part of a scholarship
system for outstanding pupils.

He has profound knowledge of web development (PHP, HTML, CSS/LESS, and


AngularJS), and has worked with a variety of other programming languages and
systems, such as Java/Groovy, Grails, Objective-C and Swift, Matlab, C (with Cilk),
Node.js, and Linux servers.

Furthermore, he works with some database management systems based on SQL


and also some NoSQL systems, such as MongoDB and SOLR; this is also reflected
in several projects that he is currently involved in at Catalysts GmbH.

After studying abroad as an exchange student in the United Kingdom, he completed


his bachelor's degree at the Johannes Kepler University in Linz, Austria, with a thesis
on aerosol satellite data processing for mobile visualization; this is where he also
became familiar with processing large amounts of data.

Daniel enjoys solving challenging problems and is always keen on working with new
technologies, especially related to the fields of big data, functional programming,
optimization, and NoSQL databases.

More detailed information about his experience , as well as his contact details, can be
found at www.muehlbachler.org and www.linkedin.com/in/danielmuehlbachler.
Weiwei Sun is a student of Southeast University, China, and also a student of
Monash University, Australia. He also has a double master's degree in computer
technology and information technology. He loves technology, programming, and
open source projects.

His research interests are database technology, data visualization, and application of
machine learning.

You can read more about him at http://wwsun.github.com.

Mehdi Tazi is a software engineer specializing in distributed information systems


and agile project management.

His core expertise involves managing agile scrum teams, as well as architecting
new solutions, and working with multiple technologies, such as JAVA/JEE, Spring,
MongoDB, Cassandra, HTML5, Bootstrap, and AngularJS.

He has a degree in software engineering and a master's degree in business


informatics. He also has several certifications, such as Core-Spring, MongoDB,
Cassandra, and Scrum Master Official.

You can read more about him at http://tazimehdi.com.


www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles,


sign up for a range of free newsletters and receive exclusive discounts and offers
on Packt books and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
This book is dedicated to all the guys that patiently answered my questions
on MongoDB forums and to my son Alessandro that taught me
how to play 'Magic the Gathering' while waiting for replies
Table of Contents
Preface v
Chapter 1: Introduction to MongoDB 1
Getting into the NoSQL movement 1
Comparing RDBMS and NoSQL databases 4
Living without transactions 6
Managing read-write concurrency 7
MongoDB core elements 8
The heart of MongoDB – the document 9
Understanding how MongoDB stores data 10
Data types accepted in documents 11
Installing and starting MongoDB 12
Installing MongoDB on Windows 12
Installing MongoDB on Linux 13
MongoDB start up options 14
Troubleshooting MongoDB installation 15
Mongo tools 16
Introduction to the MongoDB shell 18
Inserting documents 19
Querying documents 19
Choosing the keys to return 20
Using ranges in your queries 21
Using logical operators to query data 22
Updating documents 22
Deleting data 24
Beyond basic data types 25
Arrays 25
Embedded documents 26
Some useful functions 27
Securing database access 28
Summary 30
[i]
Table of Contents

Chapter 2: Getting Started with Java Driver for MongoDB 31


Getting the Mongo JDBC driver 31
Creating your first project 32
Creating a new Java project 32
Handling authentication 35
Inserting a document 36
Creating embedded documents 38
Inserting an array of data 38
Using your own ID in documents 40
Querying data 41
Restricting the search to the first document 43
Querying the number of documents in a collection 43
Eager fetching of data using DBCursor 43
Filtering through the records 44
Updating documents 45
Deleting documents 46
Deleting a set of documents 47
Performing operations on collections 47
Listing collections 48
Dropping a collection 49
Using the MongoDB Java driver version 3 49
Running the HelloWorld class with driver v.3 50
Managing collections 51
Inserting data into the database 51
Inserting embedded documents 52
Inserting multiple documents 53
Querying documents 53
Filtering through documents 54
Updating documents 55
Deleting documents 56
Summary 56
Chapter 3: MongoDB CRUD Beyond the Basics 57
Seeing MongoDB through the Java lens 57
Extending the MongoDB core classes 58
Using the Gson API with MongoDB 62
Downloading the Gson API 62
Using Gson to map a MongoDB document 63
Inserting Java objects as a document 65
Mapping embedded documents 66
Custom field names in your Java classes 68
Mapping complex BSON types 69
Using indexes in your applications 72
Defining an index in your Java classes 75
Using compound indexes 77

[ ii ]
Table of Contents

Using text indexes in your documents 80


Coding bulk operations 83
Comparing plain inserts with BulkWriteOperations 84
Summary 85
Chapter 4: MongoDB in the Java EE 7 Enterprise Environment 87
Entering into the Java EE land 87
Getting a Java EE Container 89
Downloading WildFly 89
Starting WildFly and testing the installation 90
Designing our application 90
Designing the schema 91
Building up the Enterprise project with NetBeans 92
Configuring WildFly on NetBeans 92
Creating our project 94
Adding Java classes 99
Compiling and deploying the project 107
Compiling and deploying from the shell 107
Running the application 108
Exposing the application to external clients 109
Adding RESTful web services to our application 109
Compiling and deploying the application 112
Summary 113
Chapter 5: Managing Data Persistence with
MongoDB and JPA 115
An overview of the Java Persistence API 115
Entering Hibernate OGM 117
Building a JPA project that uses Hibernate OGM 119
Configuring the project dependencies 121
Mapping the database collections 122
Configuring persistence 125
Coding the controller and EJB classes 126
Hibernate OGM and JP-QL 128
Coding a controller bean 129
Coding the views 131
The main view 132
The newCustomer view 133
The newOrder view 134
Compiling and running the example 135
A look into MongoDB 137
Using native queries in your Hibernate OGM 138
Summary 139

[ iii ]
Table of Contents

Chapter 6: Building Applications for MongoDB with


Spring Data 141
Introducing Spring Boot 141
Getting started with Spring Boot 142
Getting started with Spring Data 143
Using the Spring repository to access MongoDB 144
Coding our Spring Boot application 145
Serving MongoDB using Spring REST 153
Using the Mongo template component to access MongoDB 157
Building up the data access layer 157
Adding the Application class 160
Creating fine grained queries using Criteria 161
Summary 163
Index 165

[ iv ]
Preface
The NoSQL movement is growing in relevance, and it is attracting more and more
developers. The MongoDB database is a well-recognized rising star in the NoSQL
world. It is a document database that allows data to persist and query data in a
nested state without any schema constraint and complex joins between documents.
Understanding when it is appropriate to use MongoDB against a relational database
and the interfaces to be used to interact with it requires some degree of experience.

This book provides all the knowledge to make MongoDB fit into your application
schema, at the best of its capabilities. It starts from a basic introduction to the driver
that can be used to perform some low level interaction with the storage. Then it
moves on to use different patterns for abstracting the persistence layer into your
applications, starting from the flexible Google JSON library, to the Hibernate OGM
framework, and finally landing on the Spring Data framework.

What this book covers


Chapter 1, Introduction to MongoDB, covers the installation steps of MongoDB and its
client tools and how to use the Mongo shell to perform basic database operations.

Chapter 2, Getting Started with Java Driver for MongoDB, introduces the Java
Driver for MongoDB using a simple Java project developed with the NetBeans
development environment.

Chapter 3, MongoDB CRUD Beyond the Basics, covers the advanced usage of the
MongoDB Java driver such as data mapping, index creation, and bulk operations.

Chapter 4, MongoDB in the Java EE 7 Enterprise Environment, demonstrates how to


create and deploy a Java Enterprise application that uses MongoDB as the storage.

[v]
Preface

Chapter 5, Managing Data Persistence with MongoDB and JPA, covers the development
of a Java Enterprise application using Hibernate Object/Grid Mapper (OGM), which
provides Java Persistence API (JPA) support for NoSQL databases.

Chapter 6, Building Applications for MongoDB with Spring Data, teaches you how
to use Spring Data and Spring Boot to leverage micro services using MongoDB
as the storage.

What you need for this book


The following software will be needed to run the examples contained in this book:

• Java Development Kit 1.7 or newer


• Mongo DB 2.6 or newer
• MongoDB JDBC Driver 2 and 3
• The NetBeans development environment (or equivalent)

All the software mentioned is freely available for downloading.

Who this book is for


This book is for Java developers and architects who want to learn how to develop
Java applications using the most popular NoSQL solution and its use cases.

Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"In command prompt, navigate to the bin directory present into the mongodb
installation folder and point to the folder where data is stored."

A block of code is set as follows:


MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
DB db = mongoClient.getDB( "test" );
System.out.println("Successfully connected to MongoDB");

[ vi ]
Preface

When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
DB db = mongoClient.getDB( "test" );
System.out.println("Successfully connected to MongoDB");

Any command-line input or output is written as follows:


> db.users.find({}).sort({"name":1})

{ "_id" : ObjectId("5506d5708d7bd8471669e674"), "name" : "francesco",


"age" : 44, "phone" : "123-456-789" }
{ "_id" : ObjectId("550ad3ef89ef057ee0671652"), "name" : "owen", "age" :
32, "phone" : "555-444-333" }

New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: " Now let's
add a Java class to the project. From the File menu, select Java Class under New ".

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to feedback@packtpub.com,


and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.

[ vii ]
Preface

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.

Downloading the example code


You can download the example code files for all Packt books you have purchased
from your account at http://www.packtpub.com. If you purchased this book
elsewhere, you can visit http://www.packtpub.com/support and register to have
the files e-mailed directly to you.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you find a mistake in one of our books—maybe a mistake in the text or the
code—we would be grateful if you would report this to us. By doing so, you can save
other readers from frustration and help us improve subsequent versions of this book.
If you find any errata, please report them by visiting http://www.packtpub.com/
submit-errata, selecting your book, clicking on the errata submission form link,
and entering the details of your errata. Once your errata are verified, your submission
will be accepted and the errata will be uploaded on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be
viewed by selecting your title from http://www.packtpub.com/support.

Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected


pirated material.

We appreciate your help in protecting our authors, and our ability to bring you
valuable content.

Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.
[ viii ]
Chapter 1

Introduction to MongoDB
In this book, you will learn how to develop Java applications using the MongoDB
database, which is an open source document-oriented database, recognized as a
rising star in the NoSQL world. In a nutshell, MongoDB is a document database,
which allows data to persist in a nested state, and importantly, it can query that
nested data in an ad hoc fashion. It enforces no schema, so documents can optionally
contain fields or types that no other document in the collection contains.

The focus of this book is on applications development; however, we will at first


gather all the resources to connect to MongoDB and add a quick introduction to
the world of NoSQL databases. We will cover the following topics in more detail:

• A bird's eye view of the NoSQL landscape


• Installing MongoDB and client tools
• Using the MongoDB shell

Getting into the NoSQL movement


NoSQL is a generic term used to refer to any data store that does not follow the
traditional RDBMS model—specifically, the data is nonrelational and it generally
does not use SQL as a query language. Most of the databases that are categorized
as NoSQL focus on availability and scalability in spite of atomicity or consistency.

This seems quite a generic definition of NoSQL databases; however, all databases
that fall into this category have some characteristics in common such as:

• Storing data in many formats: Almost all RDBMS databases are based on
the storage or rows in tables. NoSQL databases, on the other hand, can use
different formats such as document stores, graph databases, key-value stores
and even more.

[1]
Introduction to MongoDB

• Joinless: NoSQL databases are able to extract your data using simple
document-oriented interfaces without using SQL joins.
• Schemaless data representation: A characteristic of NoSQL implementations
is that they are based on a schemaless data representation, with the notable
exception of the Cassandra database (http://cassandra.apache.org/).
The advantage of this approach is that you don't need to define a data
structure beforehand, which can thus continue to change over time.
• Ability to work with many machines: Most NoSQL systems buy you the
ability to store your database on multiple machines while maintaining
high-speed performance. This brings the advantage of leveraging low cost
machines with separate RAM and disk and also supports linear scalability.

On the other hand, all database developers and administrators know the ACID
acronym. It says that database transactions should be:

• Atomicity: Everything in a transaction either succeeds or is rolled back


• Consistency: Every transaction must leave the database in a consistent state
• Isolation: Each transaction that is running cannot interfere with other
transactions
• Durability: A completed transaction gets persisted, even after
applications restart

At first glance, these qualities seem vital. In practice, however, for many
applications, they are incompatible with the availability and performance in
very large environments. As an example, let's suppose that you have developed an
online book store and you want to display how many of each book you have in your
inventory. Each time a user is in the process of buying a book, you need to lock part
of the database until they finish so that every visitors from the world will see the
exact inventory numbers. That works just fine for a small homemade site but not if
you run Amazon.com. For this reason, when we talk about NoSQL databases, or,
generally, if we are designing distributed systems, we might have to look beyond the
traditional ACID properties. As stated by the CAP theorem, coined by Eric Brewer,
the following set of requirements are truly essential when designing applications for
distributed architectures:

• Consistency: This means the database mostly remains adherent to its rules
(constraints, triggers, and so on) after the execution of each operation and
that any future transaction will see the effects of the earlier transactions
committed. For example, after executing an update, all the clients see the
same data.
• Availability: Each operation is guaranteed a response—a successful or failed
execution. This, in practice, means no downtime.

[2]
Chapter 1

• Partition tolerance: This means the system continues to function even if the
communication among the servers is temporarily unreliable (for example, the
servers involved in the transaction may be partitioned into multiple groups,
which cannot communicate with one another).

In practice, as it is theoretically impossible to have all three requirements met, a


combination of two must be chosen and this is usually the deciding factor in what
technology is used, as shown in the following figure:

If you are designing a typical web application that uses a SQL database, most likely,
you are in the CA part of the diagram. This is because a traditional RDBMS is
typically transaction-based (C) and it can be highly available (A). However, it cannot
be Partition Tolerance (P) because SQL databases tend to run on single nodes.

MongoDB, on the other hand, is consistent by default (C). This means if you perform
a write on the database followed by a read, you will be able to read the same data
(assuming that the write was successful).

Besides consistency, MongoDB leverages Partition Tolerance (P) by means of replica


sets. In a replica set, there exists a single primary node that accepts writes, and
asynchronously replicates a log of its operations to other secondary databases.

[3]
Introduction to MongoDB

However, not all NoSQL databases are built with the same focus. An example of
this is CouchDB. Just like MongoDB, it is document oriented and has been built to
scale across multiple nodes easily; on the other hand, while MongoDB (CP) favors
consistency, CouchDB favors availability (AP) in spite of consistency. CouchDB uses
a replication model called Eventual Consistency. In this model, clients can write
data to one database node without waiting for acknowledgment from other nodes.
The system takes care to copy document changes between nodes, so that they can
eventually be in sync.

The following table summarizes the most common NoSQL databases and their
position relative to CAP attributes:

Database Consistent, Partition- Available, Partition-Tolerant


Tolerant (CP) (AP)
BigTable X
Hypertable X
HBase X
MongoDB X
Terrastore X
Redis X
Scalaris X
MemcacheDB X
Berkeley DB X
Dynamo X
Voldemort X
Tokyo Cabinet X
KAI X
Cassandra X
CouchDB X
SimpleDB X
Riak X

Comparing RDBMS and NoSQL databases


As you might guess, there is no absolute winner between traditional databases and
the new NoSQL standard. However, we can identify a set of pros and cons related to
each technology. This can lead to a better understanding of which one is most fit for
our scenarios. Let's start from traditional RDBMS:

[4]
Chapter 1

RDBMS pros RDBMS cons


ACID transactions at the database level The object-relational mapping layer can be
make development easier. complex.
Fine-grained security on columns and RDBMS doesn't scale out when joins are
rows using views prevents views and required.
changes by unauthorized users. Most SQL
code is portable to other SQL databases,
including open source options.
Typed columns and constraints will Sharding over many servers can be done
validate data before it's added to the but requires application code and will be
database and increase data quality. operationally inefficient.
The existing staff members are already Full-text search requires third-party tools.
familiar with entity-relational design and
SQL.
Well-consolidated theoretical basis and Storing high-variability data in tables can be
design rules. challenging.

The following is a table that contains the advantages and disadvantages of NoSQL
databases:

NoSQL pros NoSQL cons


It can store complex data types (such as There is a lack of server-side transactions;
documents) in a single item of storage. therefore, it is not fit for inherently
transactional systems.
It allows horizontal scalability, which does Document stores do not provide fine-grained
not require you to set up complex joins security at the element level.
and data can be easily partitioned and
processed in parallel.
It saves on development time as it is NoSQL systems are new to many staff
not required to design a fine-grained members and additional training may
data model. be required.
It is quite fast for inserting new data and The document store has its own proprietary
for simple operations or queries. nonstandard query language, which
prohibits portability.
It provides support for Map/Reduce, There is an absence of standardization. No
which is a simple paradigm that allows standard APIs or query languages. It means
for scaling computation on a cluster of that migration to a solution from different
computing nodes. vendors is more costly. Also, there are no
standard tools (for example, for reporting).

[5]
Introduction to MongoDB

Living without transactions


As you can imagine, one of the most important factors when deciding to use
MongoDB or traditional RDBMS is the need for transactions.

With an RDBMS, you can update the database in sophisticated ways using SQL and
wrap multiple statements in a transaction to get atomicity and rollback. MongoDB
doesn't support transactions. This is a solid tradeoff based on MongoDB's goal of
being simple, fast, and scalable. MongoDB, however, supports a range of atomic
update operations that can work on the internal structures of a complex document.
So, for example, by including multiple structures within one document (such as
arrays), you can achieve an update in a single atomic way, just like you would do
with an ordinary transaction.

As documents can grow in complexity and contain several nested


documents, single-document atomicity can be used as a replacement
for transactions in many scenarios.

On the other hand, operations that includes multiple documents (often referred to as
multi-document transactions), are conversely not atomic.

In such scenarios, when you need to synchronize multi-document transactions, you


can implement the 2PC (two-phase commit) in your application so that you can
provision these kinds of multidocument updates. Discussing about this pattern,
however, is out of the scope of this book, but if you are eager to know more, you
can learn more from http://docs.mongodb.org/manual/tutorial/perform-
two-phase-commits/.

So, to sum it up, if your application's requirements can be met via document updates
(also by using nested documents to provide an atomic update), then this is a perfect
use case for MongoDB, which will allow a much easier horizontal scaling of your
application.

On the other hand, if strict transaction semantics (such as a banking application) are
required, then nothing can beat a relational database. In some scenarios, you can
combine both approaches (RDBMS and MongoDB) to get the best of both worlds,
at the price of a more complex infrastructure to maintain. Such hybrid solutions are
quite common; however, you can see them in production apps such as the New York
Times website.

[6]
Exploring the Variety of Random
Documents with Different Content
It was not very far from sunset, and the small birds were already
singing among the boughs, and the deep shadow—the antique and
neglected air and the silence of the place—gave it, in his romantic
eyes, a character of monastic mystery and enchantment.
As he gazed straight up the dark walk towards the house,
suddenly a man turned the corner of the yew hedge that met the
bridge’s parapet close to him, and walking straight up to the door,
with a gruff look at the little boy, shut and locked the wooden door in
his face.
So all was gone for the present. He knew there was no good in
looking through the key-hole, for envious fortune had hung a spray of
sweetbriar so as effectually to intercept the view, and nothing
remained but the dingy chocolate-coloured planks before him, and
the foliage and roses trembling over the old wall.
Many a time again he passed and re-passed the door without a
like good hap.
At length, however, one evening he found the envious wooden
door once more open, and the view again disclosed through the iron
bars.
A very pretty little girl, with golden hair, was standing on tip-toe
near, and with all her soul was striving to reach an apple with a stick
which she held in her tiny fingers.
Seeing him she fixed her large eyes on him, and said, with an air
of command—
“Come, and climb up the tree and get me that apple.”
His heart beat quick—there was nothing he liked better.
“But I can’t get in,” he said, blushing; “the door is locked.”
“Oh! I’ll call mamma—she’ll let you in. Don’t you know mamma?”
“No, I never saw her,” answered the boy.
“Wait there, and I’ll fetch her.”
And so she was gone.
The first flutter of his excitement was hardly over when he heard
steps and voices near, and the little girl returned, holding the hand of
a slight, pale lady, with a very pretty face, dressed all in black. She
had the key in her hand, and smiled gently on the little boy as she
approached. Her face was kind, and at once he trusted her.
“Oh! he has left the inner door open again,” she said, and with a
little nod and smile of welcome she opened the door, and the boy
entered the garden.
Both doors were now shut.
“Look up, little boy,” said the lady in black, with a very sweet voice.
She liked his face. He was a very handsome little fellow, and with
an expression earnest, shy, and bright, and the indescribable
character of refinement too in his face. She smiled more kindly still,
and placing just the tip of her finger under his chin she said—
“You are a gentleman’s son, and you are nicely dressed. What is
your name?”
“My papa’s name is Mr. Henry,” he answered.
“And where do you go to school?”
“I don’t go to school. I say lessons to Mr. Wharton—about half a
mile from this.”
“It is great fun, I suppose, playing with the little boys—cricket, and
all that?”
“I’m not allowed to play with the little boys.”
“Who forbids you?”
“My friends won’t allow me.”
“Who are your friends?”
“I never saw them.”
“Really! and don’t you live with your papa?”
“No, I live with Marjory.”
“Do you mean with your mamma?”
“Oh, no. She died a long time ago.”
“And is your papa rich—why aren’t you with him?”
“He was rich, Granny says, but he grew poor.”
“And where is he now?”
“I don’t know. I’m to go to school,” he said, acquiring confidence
the more he looked in that sweet face. “My friends will send me, in
three years, Granny says.”
“You are a very nice little boy, and I’m sure a good little fellow.
We’ll have tea in a few minutes—you must stay and drink tea with
us.”
The little fellow held his straw hat in his hand, and was looking up
in the face of the lady, whose slender fingers were laid almost
caressingly on his rich brown hair as she looked down smiling, with
eyes in which “the water stood.” Perhaps these forlorn childhoods
had a peculiar interest for her.
“And it is very polite of you taking off your hat to a lady, but put it
on again, for I’m not a bit better than you; and I’ll go and tell them to
get tea now. Dulcibella,” she called. “Dulcibella, this little friend is
coming to drink tea with us, and Amy and he will play here till it
comes, and don’t mind getting up, sit quiet and rest yourself.”
And she signed with her hand, smiling, to repress her attempt to
rise.
“Well, darling, play in sight o’ me, till your mamma comes back,”
said the rheumatic old woman, addressing the little girl; “and ye
mustn’t be pulling at that great rolling-stone; ye can’t move it, and ye
may break your pretty back trying.”
With these and similar injunctions the children were abandoned to
their play.
He found this pretty young lady imperious, but it was pleasant to
be so commanded, and the little boy climbed trees to gather her
favourite apples, and climbed the garden wall to pluck a bit of
wallflower, and at last she said—
“Now, we’ll play ninepins. There’s the box, set them up on the
walk. Yes, that’s right; you have played; who taught you?”
“Granny.”
“Has Granny ninepins?”
“Yes, ever so much bigger than these.”
“Really! So Granny is rich, then?”
“I think so.”
“As rich as mamma?”
“Her garden isn’t so big.”
“Begin, do you; ah, ha! you’ve hit one, and who plays best?”
“Tom Orange does; does your mamma know Tom Orange?”
“I dare say she does. Dulcibella, does mamma know Tom
Orange?”
“No, my dear.”
“No, she doesn’t,” echoed the little girl, “who is he?”
What, not know Tom Orange! How could that be? So he narrated
on that brilliant theme.
“Tom Orange must come to tea with mamma, I’ll tell her to ask
him,” decided the young lady.
So these little wiseacres pursued their game, and then had their
tea, and in about an hour the little boy found himself trudging home,
with a sudden misgiving, for the first time, as to the propriety of his
having made these acquaintances without Granny’s leave.
The kind voice, the beloved smile of Granny received him before
the cottage door.
“Welcome, darlin’, and where was my darlin’, and what kept him
from his old Granny?”
So they hugged and kissed, and then he related all that had
happened, and asked “was it any harm, Granny?”
“Not a bit, darlin’, that’s a good lady, and a grand lady, and a fit
companion for ye, and see how she knew the gentle blood in your
pretty face; and ye may go, as she has asked you, to-morrow
evening again, and as often as she asks ye; for it was only the little
fellows that’s going about without edication or manners, that your
friends, and who can blame them, doesn’t like ye to keep company
with—and who’d blame them, seeing they’re seldom out of mischief,
and that’s the beginning o’ wickedness, and you’re going, but oh!
darlin’, not for three long years, thank God, to a grand school where
there’s none but the best.”
So this chance acquaintance grew, and the lady seemed to take
every week a deeper interest in the fine little boy, so sensitive,
generous, and intelligent, and he very often drank tea with his new
friends.
CHAPTER LIX.
AN OLD FRIEND.

I am going now to describe the occurrences of a particular evening


on which my young friend drank tea at Stanlake Farm, which was the
name of the house with the old garden to which I have introduced
the reader.
A light shower had driven the party in from the garden, and so the
boy and Amy were at their ninepins in the great hall, when, the door
being open, a gentleman rode up and dismounted, placing the bridle
in the hand of a groom who accompanied him.
A tall man he was, with whiskers and hair dashed with white, and
a slight stoop. He strode into the hall, his hat on, and a whip still in
his hand.
“Hollo! So there you are—and how is your ladyship?” said he.
“Skittles, by the law! Brayvo! Two down, by Jove! I’d rather that
young man took you in hand than I. And tell me—where’s Ally?”
“Mamma’s in the drawing-room,” said the young lady, scarcely
regarding his presence. “Now play, it’s your turn,” she said,
addressing her companion.
The new arrival looked at the boy and paused till he threw the ball.
“That’s devilish good too,” said the stranger—“very near the nine.
Eh? But a miss is as good as a mile; and I don’t think he’s quite as
good as you—and she’s in the drawing-room; which is the drawing-
room?”
“Don’t you know the drawing-room! Well, there it is,” and the
young lady indicated it with her finger. “My turn now.”
And while the game was pursued in the hall, the visitor pushed
open the drawing-room door and entered.
“And how is Miss Ally?”
“Oh, Harry! Really!”
“Myself as large as life. You don’t look half pleased, Ally. But I
have nout but good news for you to-day. You’re something richer this
week than you were last.”
“What is it, Harry? Tell me what you mean?”
“So I will. You know that charge on Carwell—a hundred and forty
pounds a year—well, that’s dropped in. That old witch is dead—ye
might ’a seen it in the newspaper, if you take in one—Bertha
Velderkaust. No love lost between ye. Eh?”
“Oh, Harry! Harry! don’t,” said poor Alice, pale, and looking
intensely pained.
“Well, I won’t then; I didn’t think ’twould vex you. Only you know
what a head devil that was—and she’s dead in the old place,
Hoxton. I read the inquest in the Times. She was always drinkin’. I
think she was a bit mad. She and the people in the back room were
always quarrelling; and the father’s up for that and forgery. But
’twasn’t clear how it came about. Some swore she was out of her
mind with drink, and pitched herself out o’ the window; and some
thought it might ’a bin that chap as went in to rob her, thinkin’ she
was stupid; and so there was a tussle for’t—she was main strong, ye
know—and he chucked her out. Anyhow she got it awful, for she fell
across the spikes of the area-rails, and she hung on them with three
lodged in her side—the mad dog-fox, she was!”
“Oh, Harry! How shocking! Oh! pray don’t!” exclaimed Alice, who
looked as if she was going to faint.
“Well, she lay there, without breath enough to screech, twistin’ like
a worm—for three hours, it’s thought.”
“Oh! Harry—pray don’t describe it; don’t, I implore. I feel so ill.”
“Well, I won’t, if you say so, only she’s smashed, and cold in her
wooden surtout; and her charge is reverted to you, now; and I
thought I’d tell ye.”
“Thank you, Harry,” she said, very faintly.
“And when did you come here? I only heard this morning,” asked
Harry.
“Five weeks ago.”
“Do you like it; ain’t it plaguy lonesome?”
“I like the quiet—at least for a time,” she answered.
“And I’m thinkin’ o’ gettin’ married—upon my soul I am. What do
you think o’ that?”
“Really!”
“Sure as you’re there, but it won’t be none o’ your love-matches.
‘Bring something, lass, along wi’ thee,
If thou intend to live wi’ me.’
That’s my motto. Sweetheart and honey-bird keeps no house, I’ve
heard say. I like a body that can look after things, and that would
rather fund fifty pounds than spend a hundred.
‘A nice wife and a back door
Hath made many a rich man poor,’
as they say; and besides, I’m not a young fellow no longer. I’m
pushin’ sixty, and I should be wise. And who’s the little chap that’s
playin’ skittles wi’ Amy in the hall?”
“Oh, that’s such a nice little boy. His father’s name is Henry, and
his mother has been dead a long time. He lives with a good old
woman named Marjory Trevellian. What’s the matter, Harry?”
“Nothing. I beg your pardon. I was thinkin’ o’ something else, and I
didn’t hear. Tell me now, and I’ll listen.”
So she repeated her information, and Harry yawned and stretched
his arms.
“‘For want o’ company,
Welcome trumpery,’
and I must be goin’ now. I wouldn’t mind drinkin’ a glass o’ sherry, as
you’re so pressing, for I’ve had a stiff ride, and dust’s drouthy.”
So Harry, having completed his visit characteristically, took his
leave, and mounted his nag and rode away.
CHAPTER LX.
TOM ORANGE.

Little Miss Amy had a slight cold, and the next tea-party was put off
for a day. On the evening following Harry’s visit at Stanlake Farm,
Marjory Trevellian being at that time absent in the village to make
some frugal purchases, who should suddenly appear before the little
boy’s eyes, as he lifted them from his fleet upon the pond, but his
friend, Tom Orange, as usual in high and delightful spirits.
Need I say how welcome Tom was? He asked in a minute or two
for Marjory, and took her temporary absence with great good
humour. Tom affected chilliness, and indeed the evening was a little
sharp, and proposed that they should retire to the cottage, and sit
down there.
“How soon do you suppose, youngster, the old hen will come
home?”
“Who?”
“Marjory Daw, down the chimney.”
“Oh, Granny?”
This nickname was the only pleasantry of Mr. Orange which did
not quite please the boy.
Tom Orange here interpolated his performance of the jackdaw,
with his eyelids turned inside out and the pupils quivering, which,
although it may possibly have resembled the jackdaw of heraldry,
was not an exact portraiture of the bird familiar to us in natural
history; and when this was over he asked again—“How soon will she
be home?”
“She walked down to the town, and I think she can’t be more than
about half-way back again.”
“That’s a mile, and three miles an hour is the best of her paces if
she was runnin’ for a pound o’ sausages and a new cap. Heigh ho!
and alas and alack-a-day. No one at home but the maid, and the
maid’s gone to church! I wrote her a letter the day before yesterday,
and I must read it again before she comes back. Where does she
keep her letters?”
“In her work-box on the shelf.”
“This will be it, the wery identical fiddle!” said Tom Orange,
playfully, setting it down upon the little deal table, and, opening it, he
took out the little sheaf of letters from the end, and took them one by
one to the window, where he took the liberty of reading them.
I think he was disappointed, for he pitched them back again into
their nook in the little trunk-shaped box contemptuously.
The boy regarded Tom Orange as a friend of the family so
confidential, and as a man in all respects so admirable and virtuous,
that nothing appeared more desirable and natural than that excellent
person’s giving his attention to the domestic correspondence.
He popped the box back again in its berth. Then he treated the
young gentleman to Lingo’s song with the rag-tag-merry-derry
perrywig and hat-band, &c., and at the conclusion of the
performance admitted that he was “dry,” and with a pleasant wink,
and the tip of his finger pushing the end of his nose a good deal to
the left, he asked him whether he could tell him where Mrs.
Trevellian, who would be deeply grieved if she thought that Tom was
detained for a drink till her return, kept her liquor.
“Yes, I can show you,” said the boy.
“Wait a minute, my guide, my comforter, and friend,” said Tom
Orange; and he ascertained from the door-stone that no one was
inconveniently near.
The boy was getting a tea-cup off the shelf.
“Never mind sugar, my hero, I’ll sweeten it with a thought of
Marjory Daw.”
The boy explained, and led him into the dark nook by the hall door.
Tom Orange, well pleased, moved almost on tiptoe, and looked
curiously and spoke under his breath, as he groped in this twilight.
“Here it is,” said the boy, frankly.
“Where?”
“Here.”
“This!” said Tom, for his friend had uncovered a crock of water.
Tom Orange glared at him and at the water with grotesque
surprise, and the bona fides of the boy and the simplicity of the
situation struck Tom comically, and, exploding good-humouredly, he
sat down in Marjory’s chair and laughed hilariously.
Having satisfied himself by a confidential dialogue that Marjory
Daw had no private bottle of comfort anywhere, this agreeable fellow
so far forgot his thirst, that he did not mind drawing water from the
crock, and talked on a variety of subjects to the young gentleman. In
the course of this conversation he asked him two topographical
questions. One was—
“Did you ever hear of a place called Carwell Grange?”
And the other resembled it.
“Did you ever hear of a place called Wyvern?”
“No.”
“Think, lad. Did you never hear Mrs. Trevellian speak of Wyvern?
Or of Carwell Grange?”
“No.”
“Because there is the tallest mushroom you ever saw in your life
growing there, and it is grown to that degree that it blocks the door
so that the Squire can’t get into his own house, and the mushroom is
counted one of the wonders of the world upon my little word of
honour as a gentleman! And
‘Since there’s neither drink nor victuals,
Suppose, my lord, we play at skittles?’
And if she’s not back by the end of the game, tell her I had to go on
to the bridge to see lame Bill Withershins, and I’ll be back again this
evening, I think, or in the morning at latest.”
The game was played, but Marjory did not appear, and Tom
Orange, entertaining his young friend with a ludicrous imitation of Bill
Withershins’ knock-knees, took his departure, leaving his delighted
companion in the state which Moore describes as being usual—
“When the lamp that lighted
The traveller at first goes out.”
So, having watched Tom till he was quite out of sight, he returned
to his neglected navy on the pond, and delivered his admirable
Crichton’s message to Marjory Daw on her return.
CHAPTER LXI.
THE HOUR AND THE MAN.

Supper-time came, and Tom Orange did not return. Darkness


closed over the old cottage, the poplar trees and the town, and the
little boy said his prayers under the superintendence of worthy
Marjory, and went to his bed.
He was disturbed in his sleep by voices talking in the room. He
could only keep his eyes open for a little time, and he saw Tom
Orange talking with mammy. He was at one side of the little table
and she at another, and his head was leaning forward so as to
approach uncomfortably near to the mutton-fat with a long snuff in
the middle. Mammy, as he indiscriminately called “Granny,” was
sobbing bitterly into her apron, and sometimes with streaming eyes,
speaking so low that he could not hear, to Tom Orange.
Interesting as was the scene, slumber stole him away, and when
he next wakened, Tom was gone, and mammy was sitting on the
bed, crying as if her heart would break. When he opened his eyes,
she said—
“Oh, darlin’! darlin’! My man—my own, own blessed man—my
darlin’!” and she hugged him to her heart.
He remembered transports similar when two years ago he was
very ill of a fever.
“I’m not sick, mammy, indeed; I’m quite well,” and with these
assurances and many caresses, he again fell asleep.
In the morning his Sunday clothes, to his wonder, were prepared
for him to put on. The little old faded crimson carpet-bag, which she
had always told him, to the no small content of his self-importance,
was his own, stood plump and locked on the little table under the
clock. His chair was close beside mammy’s. She had all the
delicacies he liked best for his breakfast. There was a thin little slice
of fried bacon, and a new-laid egg, and a hot cake, and tea—quite a
grand breakfast.
Mammy sat beside him very close. Her arm was round him. She
was very pale. She tried to smile at his prattle, and her eyes filled up
as often as she looked at him, or heard him speak.
Now and then he looked wonderingly in her face, and she tried to
smile her old smile and nodded, and swallowed down some tea from
her cup.
She made belief of eating her breakfast, but she could not.
When the wondering little man had ended his breakfast, with her
old kind hands she drew him towards her.
“Sit down on my lap, my precious—my own man—my beautiful
boy—my own angel bright. Oh, darlin’—darlin’—darlin’!” and she
hugged the boy to her heart, and sobbed over his shoulder as if her
heart was bursting.
He remembered that she cried the same way when the doctor said
he was safe and sure to recover.
“Mammy,” he said, kissing her, “Amy has birthdays—and I think
this is my birthday—is it?”
“No, darlin’; no, no,” she sobbed, kissing him. “No, my darlin’, no.
Oh, no, ’taint that.”
She got up hastily, and brought him his little boots that she had
cleaned. The boy put them on, wondering, and she laced them.
With eyes streaming she took up one of the little cork boats, which
he kept on the window-stool floating in a wooden bowl.
“You’ll give me one of them, darlin’—to old mammy—for a
keepsake.”
“Oh! yes. Choose a good one—the one with the gold paper on the
pin; that one sails the best of all.”
“And—and”—she cried bitterly before she could go on—“and this
is the little box I’ll put them in,” and she picked them out of the bowl
and laid them in a cardboard box, which she quickly tied round. “And
this is the last day of poor mammy with her bright only darlin’—for
your friends are sending for you to-day, and Mr. Archdale will be here
in ten minutes, and you’re to go with him. Oh, my precious—the light
o’ the house—and to leave me alone.”
The boy stood up, and with a cry, ran and threw his arms round
her, where she stood near the clock.
“Oh! no, no, no. Oh! mammy, you wouldn’t; you couldn’t, you
couldn’t.”
“Oh, darlin’, you’re breaking my heart. What can I do?”
“Don’t let me go. Oh, mammy, don’t. Oh, you couldn’t, you
couldn’t.”
“But what can I do, darlin’? Oh, darlin’, what can I do?”
“I’ll run away, mammy, I’ll run away; and I’ll come back when
they’re gone, and stay with you.”
“Oh, God Almighty!” she cried, “here he’s coming. I see him
coming down the hazel road.”
“Hide me, mammy; hide me in the press. Oh, mammy, mammy,
you wouldn’t give me to him!”
The boy had got into this large old-painted press, and coiled
himself up between two shelves. There was hardly a moment to
think; and yielding to the instinct of her desperate affection, and to
the child’s wild appeal, she locked the door, and put the key in her
pocket.
She sat down. She was half stunned by her own audacity. She
scarcely knew what she had done. Before she could recover herself,
the door darkened, a hand crossed the hatch and opened it, and ex-
Sergeant-Major Archdale entered the cottage.
In curt military fashion he announced himself, and demanded the
boy.
She was looking straight in this formidable man’s face, and yet it
seemed as if he were vanishing from before her eyes.
“Where’s the boy?” inquired the chill stern voice of the Sergeant.
It seemed to her like lifting a mountain this effort to speak. She felt
as if she were freezing as she uttered the denial.
“He aint here.”
“Where is he?” demanded the Sergeant’s imperturbably clear cold
voice.
“He’s run away,” she said with an effort, and the Sergeant seemed
to vanish quite away, and she thought she was on the point of
fainting.
The Sergeant glanced at the breakfast table, and saw that two had
taken tea together; he saw the carpet-bag packed.
“H’m?” intimated Archdale, with closed lips. He looked round the
cottage room, and the Sergeant sat down wonderfully composed,
considering the disconcerting nature of the announcement.
The ex-Sergeant-Major had in his time commanded parties in
search of deserters, and he was not a bad slaught-hound of that
sort.
“He breakfasted with you?” said he, with a cool nod toward the
table.
There was a momentary hesitation, and she cleared her voice and
said—
“Yes.”
Archdale rose and placed his fingers on the teapot.
“That’s hot,” said the Sergeant with the same inflexible dignity.
Marjory was awfully uneasy.
“He can’t be far. Which way did he go?”
“Out by the door. I can’t tell.”
The ex-Sergeant-Major might have believed her the goddess of
truth itself, or might have thought her the most impudent liar in
England. You could not have gathered in the least from his
countenance toward which view his conclusions tended.
The Sergeant’s light cold grey eye glided again round the room,
and there was another silence awfully trying to our good friend
Marjory.
CHAPTER LXII.
THE MARCH TO NOULTON FARM.

“I think, ma’am, the boy’s in the house. You’d best give him up, for
I’ll not go without him. How many rooms have you?”
“Three and a loft, sir.”
The Sergeant stood up.
“I’ll search the house first, ma’am, and if he’s not here I’ll inform
the police and have him in the Hue-and-Cry; and if you have had
anything to do with the boy’s deserting, or had a hand in making
away with him anyhow, I’ll have you in gaol and punished. I must
secure the door, and you can leave the house first, if you like best.”
“Very well, sir,” answered she.
But at this moment came a knocking and crying from within the
press.
“Oh! no—’twasn’t mammy; ’twas I that did it. Don’t take mammy.”
“You see, ma’am, you give useless trouble. Please open that door
—I shall have to force it, otherwise,” he added, as very pale and
trembling she hesitated.
Standing as he might before his commanding officer, stiff, with his
heels together, with his inflexibly serene face, full before her, he
extended his hand, and said simply, “The key, ma’am.”
In all human natures—the wildest and most stubborn—there is a
point at which submission follows command, and there was that in
the serenity of the ex-Sergeant-Major which went direct to the
instinct of obedience.
It was quite idle any longer trying to conceal the boy. With a
dreadful ache at her heart she put her hand in her pocket and
handed him the key.
As the door opened the little boy shrank to the very back of the
recess, from whence he saw the stout form of the Sergeant stooped
low, as his blue, smooth fixed countenance peered narrowly into the
dark. After a few seconds he seemed to discern the figure of the boy.
“Come, you sir, get out,” said the commanding voice of the visitor,
as the cane which he carried in his hand, paid round with wax-end
for some three inches at the extremity, began switching his little legs
smartly.
“Oh, sir, for the love of God!” cried Marjory, clinging to his hand.
“Oh, sir, he’s the gentlest little creature, and he’ll do whatever he’s
bid, and the lovingest child in the world.”
The boy had got out by this time, and looking wonderingly in the
man’s face, was unconsciously, with the wincing of pain, lifting his
leg slightly, for the sting of the cane was quite new to him.
“If I catch you at that work again I’ll give you five dozen,” said his
new acquaintance.
“Is this his?” said he, touching the carpet-bag with his cane.
“Yes, sir, please.”
He took it in his hand, and glanced at the boy—I think it was in his
mind to make him carry it. But the child was slender, and the bag,
conscientiously packed with everything that had ever belonged to
him, was a trifle too heavy.
“Anything else?” demanded the Sergeant-Major.
“This—this, God bless him.”
It was the little box with his ships.
“And this;” and she thrust the griddle cake, broken across and
rolled up in brown paper, into the boy’s pocket.
“And these;” and three apples she had ready, she thrust after
them.
“And ho! my blessed darlin’, my darlin’, darlin’, darlin’.”
He was lifted up against her heart, folded fast, and hugging her
round the neck, they kissed and cried and cried and kissed, and at
last she let him down; and the Sergeant-Major, with the cane under
his arm, the carpet-bag in one hand, and the boy’s wrist firmly held in
the other, marched out of the door.
“That’s enough—don’t follow, woman,” said he, after they had
gone about twenty yards on the path; “and I’ll report you,” he added
with a nod which, with these pleasant words, she might take as a
farewell or not as she pleased.
She stood on the little rising ground by the hawthorn-tree, kissing
her hands wildly after him, with streaming eyes.
“I’ll be sure to see you soon. I’d walk round the world barefoot to
see my pretty man again,” she kept crying after him; “and I’ll bring
the ninepins, I’ll be sure. Mammy’s comin’, my darlin’.”
And the receding figure of the little boy was turned toward her all it
could. He was gazing over his shoulder, with cheeks streaming with
tears, and his little hand waving yearningly back to her until he was
out of sight. And after a while she turned back, and there was their
ninepins’ ground, and the tarn, and her sobs quickened almost to a
scream; and she sat down on the stone bench under the window—
for she could not bear to enter the dark cottage—and there, in Irish
phrase, she cried her fill.
In the meantime Archdale and his companion, or prisoner—which
you will—pursued their march. He still held the boy’s wrist, and the
boy cried and sobbed gently to himself all the way.
When they came down to the little hamlet called Maple Wickets he
hired a boy to carry the carpet-bag to Wunning, four miles further on,
where the Warhampton ’bus passes, as everybody knows, at half-
past twelve o’clock daily.
They resumed their march. The Sergeant was a serenely taciturn
man. He no more thought of addressing the boy than he did of
apostrophising the cane or the carpet-bag. He let him sob on, and
neither snubbed nor consoled him, but carried his head serene and
high, looking straight before him.
At length the novelty of the scene began to act upon the volatility
of childhood.
As he walked by the Sergeant he began to prattle, at first timidly,
and then more volubly.
The first instinct of the child is trust. It was a kind of consolation to
the boy to talk a great deal of his home, and Tom Orange was of
course mentioned with the usual inquiry, “Do you know Tom
Orange?”
“Why so?”
Then followed the list of that facetious and brilliant person’s
accomplishments.
“And are we to go near a place called Wyvern or Carwell Grange?”
asked the boy, whose memory, where his fancy was interested, was
retentive.
“Why so?” again demanded the Sergeant, looking straight before
him.
“Because Tom Orange told me there’s the biggest mushroom in
the world grown up there, and that the owner of the house can’t get
in, for it fills up the door.”
“Tom Orange told you that?” demanded the Sergeant in the same
way.
And the boy, supposing it incredulity on his part, assured him that
Tom, who was truth itself, had told him so only yesterday.
The Sergeant said no more, and you could not have told in the
least by his face that he had made a note of it and was going to
“report” Tom Orange in the proper quarter. And in passing, I may
mention that about three weeks later Tom Orange was peremptorily
dismissed from his desultory employments under Mr. Archdale, and
was sued for stealing apples from Warhampton orchard, and some
minor peccadillos, and brought before the magistrates, among whom
sat, as it so happened, on that occasion, Squire Fairfield of Wyvern,
who was “precious hard on him,” and got him in for more than a
month with hard labour. The urchin hireling with the carpet-bag
trudged on in front as the Sergeant-Major had commanded.
Our little friend, with many a sobbing sigh, and a great load at his
heart, yet was looking about him.
They were crossing a moor with beautiful purple heather, such as
he had never seen before. The Sergeant had let go his wrist. He felt
more at his ease every way.
There were little pools of water here and there which attracted the
boy’s attention, and made him open his box of cork boats and peep
at them. He wondered how they would sail in these dark little nooks,
and at last, one lying very conveniently, he paused at its margin, and
took out a ship and floated it, and another, and another. How quickly
seconds fly and minutes.
He was roused by the distant voice of the Sergeant-Major
shouting, “Hollo, you sir, come here.”
He looked up. The Sergeant was consulting his big silver watch as
he stood upon a little eminence of peat.
By the time he reached him the Sergeant had replaced it, and the
two or three seals and watchkey he sported were dangling at the end
of his chain upon his paunch. The Sergeant was standing with his
heels together and the point of his cane close to the side of his boot.
“Come to the front,” said the Sergeant.
“Give up that box,” said he.
The boy placed it in his hand. He uncovered it, turned over the
little navy with his fingers, and then jerked the box and its contents
over the heath at his side.
“Don’t pick one of ’em up,” said he.
“Move half a pace to the right,” was his next order.
His next command was—
“Hold out your hand.”
The boy looked in his face, surprised.
The Sergeant’s face looked not a bit angrier or a bit kinder than
usual. Perfectly serene.
“Hold out your hand, sir.”
He held it out, and the cane descended with a whistling cut across
his fingers. Another. The boy’s face flushed with pain, and his
deadened hand sunk downward. An upward blow of the cane across
his knuckles accompanied the command, “Hold it up, sir,” and a third
cut came down.
The Sergeant was strong, and could use his wrist dexterously.
“Hold out the other;” and the same discipline was repeated.
Mingled with and above the pain which called up the three great
black weals across the slender fingers of each hand, was the sense
of outrage and cruelty.
The tears sprang to his eyes, and for the first time in his life he
cried passionately under that double anguish.
“Walk in front,” said the Sergeant, serenely.
And squeezing and wringing his trembling hands together, the still
writhing little fellow marched along the path, with a bitterer sense of
desolation than ever.
The ’bus was late at Wunning; and a lady in it, struck by the
beauty and sadness of the little boy’s face, said some kind words,
and seemed to take to him, he thought, with a tenderness that made
his heart fuller; and it was a labour almost too great for him to keep
down the rising sobs and the tears that were every moment on the
point of flowing over. This good Samaritan bought a bag of what
were called “Ginger-bread nuts”—quite a little store; which Archdale
declined leaving at the boy’s discretion. But I am bound to say that
they were served out to him, from day to day, with conscientious
punctuality by the Sergeant-Major, who was strictly to be depended
on in all matters of property; and would not have nibbled at one of
those nuts though his thin lips had watered and not a soul had been
near. He must have possessed a good many valuable military
virtues, or he could not, I presume, have been where he was.
Noulton Farm is a melancholy but not an ugly place. There are a
great many trees about it. They stand too near the windows. The
house is small and old, and there is a small garden with a thick high
hedge round it.
The members of the family were few. Miss Mary Archdale was ill
when they arrived. She was the only child of the ex-Sergeant, who
was a widower; and the new inmate of the house heard of her with a
terror founded on his awe of her silent father.
They entered a small parlour, and the boy sat down in the chair
indicated by the Sergeant. That person hung his hat on a peg in the
hall, and placed his cane along the chimney-piece. Then he rang the
bell.
The elderly woman who was the female staff of the kitchen
entered. She looked frightened, as all that household did, in their
master’s presence, and watched him with an alarmed eye.
“Where’s Miss Mary?”
“A-spitting blood, sir, please.”
“Bring in supper,” said the Sergeant.
The boy sat in fear at the very corner of the table. His grief would
not let him eat, and he sipped a cup of tea that was too hot, and had
neither milk nor sugar enough. The Sergeant snuffed his candle, and
put on a pair of plated spectacles, and looked through his weekly
paper.
While he was so employed there glided into the room a very slight
girl, with large eyes and a very pale face. Her hair was brown and
rich.
The hand with which she held her shawl across was very thin; and
in her pale face and large eyes was a timid and imploring look that
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like