100% found this document useful (2 votes)
20 views71 pages

MongoDB For Java Developers Design Build and Deliver Efficient Java Applications Using The Most Advanced NoSQL Database Francesco PDF Download

The document is about the book 'MongoDB for Java Developers' by Francesco Marchioni, which guides developers on designing, building, and delivering efficient Java applications using MongoDB, a leading NoSQL database. It covers various topics including installation, CRUD operations, and integration with Java frameworks like Spring and JPA. The book aims to provide comprehensive knowledge to leverage MongoDB's capabilities effectively in application development.

Uploaded by

vukpzlre4659
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
20 views71 pages

MongoDB For Java Developers Design Build and Deliver Efficient Java Applications Using The Most Advanced NoSQL Database Francesco PDF Download

The document is about the book 'MongoDB for Java Developers' by Francesco Marchioni, which guides developers on designing, building, and delivering efficient Java applications using MongoDB, a leading NoSQL database. It covers various topics including installation, CRUD operations, and integration with Java frameworks like Spring and JPA. The book aims to provide comprehensive knowledge to leverage MongoDB's capabilities effectively in application development.

Uploaded by

vukpzlre4659
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

MongoDB for Java developers design build and

deliver efficient Java applications using the


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

Get the full ebook with Bonus Features for a Better Reading Experience on 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/

Learn Objective C for Java Developers 1st Edition James


Bucanek

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

Professional Eclipse 3 for Java Developers 1st Edition


Berthold Daum

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

HTML Professional Projects 4th Edition John W. Gosney

https://ebookname.com/product/html-professional-projects-4th-
edition-john-w-gosney/
The AH Receptor in Biology and Toxicology 1rst edition
Edition Raimo Pohjanvirta

https://ebookname.com/product/the-ah-receptor-in-biology-and-
toxicology-1rst-edition-edition-raimo-pohjanvirta/

Key buildings from prehistory to the present Plans


sections and elevations Andrew Ballantyne

https://ebookname.com/product/key-buildings-from-prehistory-to-
the-present-plans-sections-and-elevations-andrew-ballantyne/

Lectures on the History of Moral and Political


Philosophy Jonathan Wolff

https://ebookname.com/product/lectures-on-the-history-of-moral-
and-political-philosophy-jonathan-wolff/

Essentials of Foreign Exchange Trading Essentials


Series 1st Edition James Chen

https://ebookname.com/product/essentials-of-foreign-exchange-
trading-essentials-series-1st-edition-james-chen/

One Hundred Plus Deck Designs Single Level Decks Multi


Level Decks L Shaped Decks and Many More Home Planners

https://ebookname.com/product/one-hundred-plus-deck-designs-
single-level-decks-multi-level-decks-l-shaped-decks-and-many-
more-home-planners/
Ion Implantation and Activation Volume 2 1st Edition
Kunihiro Suzuki

https://ebookname.com/product/ion-implantation-and-activation-
volume-2-1st-edition-kunihiro-suzuki/
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 [email protected] 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 [email protected],


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 [email protected] 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 [email protected] 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]
Chapter 1

Managing read-write concurrency


In RDBMS, managing the execution of concurrent work units is a fundamental
concept. The underlying implementation of each database uses behind the scenes
locks or Multiversion control to provide the isolation of each work unit. On the
other hand, MongoDB uses reader/writer locks that allow concurrent readers
shared access to a resource, such as a database or collection, but give exclusive
access to a single write operation. In more detail here is how MongoDB handles
read and write locks:

• There can be an unlimited number of simultaneous readers on a database


• There can only be one writer at a time on any collection in any one database
• The writers block out the readers once a write request comes in; all the
readers are blocked until the write completes (which is also known as
writer-greedy)

Since version 2.2 of MongoDB, it is possible to restrict the scope of the lock just the
database the read or write operation was working with. If you are using MongoDB
3.0 or later, the scope of the lock is pulled in further than ever before. Now, when a
write is occurring, only the documents involved in the write operation will be locked.
In order to store information about locks, MongoDB relies on a storage engine, which
is a part of the database and is responsible for managing how data is stored on the
disk. In particular, MongoDB 3.0 comes with two storage engines:

• MMAPv1: This is the default storage engine, which uses collection-level


locking
• WiredTiger: This is the new storage engine, which ships with document-
level locking and compression (only available for the 64-bit version)

By using the WiredTiger storage engine, all write operations happen


within the context of a document-level lock. As a result, multiple
clients can modify more than one document in a single collection
at the same time. Thanks to this granular concurrency control,
MongoDB can more effectively support workloads with read, write,
and updates, as well as high-throughput concurrent workloads.

[7]
Introduction to MongoDB

MongoDB core elements


In order to understand the capabilities of MongoDB, you need to learn the core
elements the database is composed of. Actually, MongoDB is organized with a
set of building blocks, which include the following:

• Database: This is, just like for the database, the top-level element. However,
a relational database contains (mostly) tables and views. A Mongo Database,
on the other hand, is a physical container of a structure called a collection.
Each database has its own set of files on the filesystem. A single MongoDB
server typically has multiple databases.
• Collection: This is a set of MongoDB documents. A collection is the
equivalent of an RDBMS table. There can be only one collection with that
name on the database but obviously multiple collections can coexist in a
database. Typically, the collections contained in a database are related,
although they do not enforce a schema as RDBMS tables do.
• Documents: This is the most basic unit of data in MongoDB. Basically, it is
composed by a set of key-value pairs. Unlike database records, documents
have a dynamic schema, which means documents that are part of the same
collection do not need to have the same set of fields. Much the same way,
the fields contained in a document may hold different data types.

The following diagram summarizes the concepts we just discussed:

[8]
Chapter 1

The heart of MongoDB – the document


At the heart of MongoDB is the document, an ordered set of keys with associated
values. The representation of a document varies by the programming language,
but most languages have a data structure that is a natural fit, such as a map, hash,
or dictionary. Here is a very basic example of a document, which is understood
by MongoDB:
{"name" : "Francesco",
"age" : 44,
"phone":"123-567-890"}

Most documents will be more complex than this simple one and will often contain
embedded data within them. These denormalized data models allow applications
to retrieve and manipulate related data in a single database operation:
{"name" : "Francesco",
"age" : 44,
"contact" : {
"phone":"123-567-890"
}
}

As you can see from the preceding example, we have included the contact information
within the same document by using an embedded document with a single key
named contact.

Each document requires a key, which needs to be unique within a document. The keys
contained in a document are strings. Any UTF-8 character can be included in a key,
with a few exceptions:

• You cannot include the character \0 (also known as the null character) in a
key. This character is used to indicate the end of a key.
• The . and $ characters are internally used by the database so they should be
used only in limited cases. As a general rule, it is better to completely avoid
using these characters as most MongoDB drivers can generate exceptions
when they are used inappropriately.

Finally, you need to be aware that MongoDB is both type-sensitive and case-
sensitive. For example, these documents are distinct:
{"age" : 18}
{"age" : "18"}

[9]
Introduction to MongoDB

The same applies to the following documents:


{"age" : 18}
{"Age" : 18}

Understanding how MongoDB stores data


The sample documents you have seen so far should be familiar to you if you
have ever heard about JavaScript Object Notation (JSON). JSON is a human and
machine-readable open standard that simplifies data interchange and is also one of
the most used formats for data interchange in applications along with XML. JSON
is able to deal with all the basic data types used by applications such as String,
numbers, Boolean values, as well as arrays and hashes. MongoDB is able to store
JSON documents into its collections to store records. Let's see an example of a
JSON document:
{
_id":1,
"name":{
"first":"Dennis",
"last":"Ritchie"
},
"contribs":[
"Altran",
"B",
"C",
"Unix"
],
"awards":[
{
"award":"Turing Award",
"year":1983
},
{
"award":"National medal of technology",
"year":1999
}
]
}

A JSON-based database returns a set of data that can be easily parsed by most
programming languages such as Java, Python, JavaScript, and others, reducing
the amount of code you need to build into your application layer.

[ 10 ]
Chapter 1

Behind the scenes, MongoDB represents JSON documents using a binary-encoded


format called BSON. Documents encoded with BSON enhance the JSON data model
to provide additional data types and efficiency when encoding/decoding data
within different languages.

MongoDB uses a fast and lightweight BSON implementation, which is highly


traversable and supports complex structures such as embedded objects and arrays.

Data types accepted in documents


So far, we have used just two basic data types, String and Integer. MongoDB offers a
wide choice of data types, which can be used in your documents:

• String: This is the most common data type as it contains a string of text
(such as: "name": "John").
• Integer (32 bit and 64-bit): This type is used to store a numerical value
(for example, "age" : 40). Note that an Integer requires no quotes
to be placed before or after the Integer.
• Boolean: This data type can be used to store either a TRUE or a FALSE value.
• Double: This data type is used to store floating-point values.
• Min/Max keys: This data type is used to compare a value against the lowest
and highest BSON elements, respectively.
• Arrays: This type is used to store arrays or list or multiple values into one
key (for example, ["John, Smith","Mark, Spencer"]).
• Timestamp: This data type is used to store a timestamp. This can be useful
to store when a document has been last modified or created.
• Object: This data type is used for storing embedded documents.
• Null: This data type is used for a null value.
• Symbol: This data type allows storing characters such as String; however,
it's generally used by languages that use a specific symbol type.
• Date: This data type allows storing the current date or time in the Unix time
format (POSIX time).
• Object ID: This data type is used to store the document's ID.
• Binary data: This data type is used to store a binary set of data.
• Regular expression: This data type is used for regular expressions. All options
are represented by specific characters provided in alphabetical order. You will
learn more about regular expressions.
• JavaScript code: This data type is used for JavaScript code.

[ 11 ]
Introduction to MongoDB

Installing and starting MongoDB


Installing Mongo DB is much easier than most RDBMS as it's just a matter of
unzipping the archived database and, if necessary, configure a new path for data
storage. Let's look at the installation for different operating system architectures.

Installing MongoDB on Windows


For installing MongoDB on Windows, perform the following steps:

1. Download the latest stable release of MongoDB from http://www.mongodb.


org/downloads. (At the time of writing, the latest stable release is 3.0.3, which
is available as Microsoft Installer or as a ZIP file). Ensure you download the
correct version of MongoDB for your Windows system.
2. Execute the MSI Installer, or if you have downloaded MongoDB as a ZIP file,
simply extract the downloaded file to C:\drive or any other location.

MongoDB requires a data directory to store its files. The default location for the
MongoDB data folder on Windows is c:\data\db. Execute the following command
from the command prompt to create the default folder:
C:\mongodb-win32-x86_64-3.0.3>md data

In Command Prompt, navigate to the bin directory present in the mongodb


installation folder and point to the folder where data is stored:
C:\mongodb-win32-x86_64-3.0.3\bin> mongod.exe --dbpath "C:\mongodb-
win32-x86_64-3.0.3\data"

This will show the waiting for the connections message on the console output,
which indicates that the mongod.exe process is running successfully.

[ 12 ]
Chapter 1

Installing MongoDB on Linux


The installation on Linux can be different depending on your Linux distribution.
Here is a general-purpose installation process:

1. Download the latest MongoDB distribution, which is appropriate for your


OS architecture:
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-
3.0.3.tgz

2. Extract the downloaded files:


tar -zxvf mongodb-linux-x86_64-3.0.3.tgz

3. Copy files to a target directory:


mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-3.0.3/ mongodb

4. Include MongoDB scripts in the system's PATH variable:


export PATH=<mongodb-install-directory>/bin:$PATH

5. Just like we did for Windows, we will create the data folder:
mkdir -p /data/db

6. Now, you can start MongoDB much the same way as with Windows:
mongod --dbpath /data/db

[ 13 ]
Introduction to MongoDB

MongoDB start up options


The list of start up options, which can be applied to the mongod server is quite
large and is detailed at http://docs.mongodb.org/manual/reference/program/
mongod/.

The following table summarizes the most common options for a handy reference:

Option Description
--help, -h This returns the information on the options and use of
mongod.
--version This returns the mongod release number.
--config <filename> This specifies the configuration file to be used by
mongod.
--port <port> This specifies the TCP listening port on which
MongoDB listens. (the default is 27017)
--bind_ip <ip address> This specifies the IP address that mongod binds to in
order to listen for connections from applications (the
default is All interfaces.).
--logpath <path> This sends all diagnostic logging information to a log
file instead of to a standard output or to the host's
syslog system.
--logappend This appends new entries to the end of the log file
rather than overwriting the content of the log when the
mongod instance restarts.
--httpinterface This enables the HTTP interface. Enabling the interface
can increase network exposure.
--fork This enables a daemon mode that runs the mongod
process in the background. By default, mongod does
not run as a daemon.
--auth This enables authorization to control the user's
access to database resources and operations. When
authorization is enabled, MongoDB requires all clients
to authenticate themselves first in order to determine
the access for the client.
--noauth This disables authentication. It is currently the default
and exists for future compatibility and clarity.
--rest This enables the simple REST API. Enabling the REST
API enables the HTTP interface, even if the HTTP
interface option is disabled, and as a result can increase
network exposure.

[ 14 ]
Chapter 1

Option Description
--profile <level> This changes the level of database profiling (0 Off,
which means no profiling; 1 On, which only includes
slow operations; and 2 On, which includes all the
operations.)
--shutdown This safely terminates the mongod process. It is
available only on Linux systems.

In addition, the following options can be used to vary the storage of the database:

Option Description
--dbpath <path> This is the directory where the mongod instance stores
its data. The default is /data/db on Linux and OS X
and C:\data\db on Windows.
--storageEngine string This specifies the storage engine for the mongod
database. The valid options include mmapv1 and
wiredTiger. The default is mmapv1.
--directoryperdb This stores each database's files in its own folder in the
data directory. When applied to an existing system,
the --directoryperdb option alters the storage
pattern of the data directory.

Troubleshooting MongoDB installation


On startup, the server will print some version and system information and then
begin waiting for connections. By default, MongoDB listens for connections on port
27017. The server process will fail to start if the port is already used by another
process—the most common cause of it is that another instance of MongoDB is
already running on your machine.

You can stop mongod by typing Ctrl + C in the shell that is


running the server. In a clean shutdown, the mongod process
completes all running operations, flushes all data to files, and
closes all data files. Within the Securing database access section
of this chapter, we show how to use the Mongo shell to shut
down the database from the Mongo shell.

[ 15 ]
Introduction to MongoDB

The mongod command also launches a basic HTTP server that listens,
by default, on port 28017. This web server can be used to capture REST request
(see http://docs.mongodb.org/ecosystem/tools/http-interfaces/) and
to query for administrative information about your database by pointing to
http://localhost:28017 with your web browser.

You need to start mongod with the --rest option in order


to enable the web administration console.

The following screenshot depicts the web administration GUI when executed from
the browser:

Mongo tools
MongoDB ships with a set of shell commands, which can be useful to administrate
your server. We will shortly provide a description of each command, so that you can
get an initial introduction to the server administration:

• bsondump: This displays BSON files in a human-readable format


• mongoimport: This converts data from JSON, TSV, or CSV and stores them
into a collection

[ 16 ]
Chapter 1

• mongoexport: This writes an existing collection using the CSV or JSON formats
• mongodump/mongorestore: This dumps MongoDB data to disk using the
BSON format (mongodump), or restores them (mongorestore) to a live database
• mongostat: This monitors running MongoDB servers, replica sets, or clusters
• mongofiles: This reads, writes, deletes, or updates files in GridFS
• mongooplog: This replays oplog entries between MongoDB servers
• mongotop: This monitors data reading/writing on a running Mongo server

Here is an example of how to use the mongoimport tool to import a CSV-formatted


data contained in /var/data/users.csv into the collection users in the sample
database on the MongoDB instance running on the localhost port numbered 27017:
mongoimport --db sample --collection users --type csv --headerline --file
/var/data/users.csv

In the preceding example, mongoimport determines the name of files using the first
line in the CSV file, because of --headerline.

If you want to export the MongoDB documents, you can use the mongoexport tool.
Let's look at an example of how to export the collection users (part of the sampled
database), limited to the first 100 records:
mongoexport --db sampledb --collection users --limit 100 --out export.
json

As part of your daily backup strategy, you should consider using the mongodump
tool, which is a utility for creating a binary export of the contents of a database.

mongodump does not provide a backup of the local database.

The following command creates a database dump for the collection named users
contained in the database named sampled. In this case, the database is running on
the local interface on port 27017:
mongodump --db test --collection users

The preceding command will create a BSON binary file named users.bson and a
JSON file named users.metadata.json containing the documents. The files will be
created under dump/[database-name].

[ 17 ]
Introduction to MongoDB

Finally, the mongorestore program loads binary data from a database dump
created by mongodump to a MongoDB instance. mongorestore can both create a new
database and add data to an existing database:
mongorestore --collection users --db sampledb dump/sampledb/users.bson

Introduction to the MongoDB shell


MongoDB ships with a JavaScript shell that allows interaction with a MongoDB
instance from the command line. The shell is the bread-and-butter tool for
performing administrative functions, monitoring a running instance, or just inserting
documents.

To start the shell, run the mongo executable:


$ mongo
MongoDB shell version: 3.0.3
connecting to: test

The shell automatically attempts to connect to a running MongoDB server on


startup, so make sure you start mongod before starting the shell.

If no other database is specified on startup, the shell selects a default database called
test. As a way of keeping all the subsequent tutorial exercises under the same
namespace, let's start by switching to the sampledb database:
> use sampledb
switched to db sampledb

If you are coming from an RDBMS background, you might be surprised that we can
switch to a new database without formerly creating it. The point is that creating the
database is not required in MongoDB. Databases and collections are first created
when documents are actually inserted. Hence, individual collections and databases
can be created at runtime just as the structure of a document is known.

If you want to check the list of available databases, then you can use the show dbs
command:
>show dbs
local 0.78125GB
test 0.23012GB

As you can see, the database we created (sampledb) is not present in the list. To
display the database, you need to insert at least one document into it. The next
section will show you how to do it.

[ 18 ]
Chapter 1

Inserting documents
As we said, MongoDB documents can be specified in the JSON format. For example,
let's recall the simple document that we have already introduced:
{"name" : "francesco",
"age" : 44,
"phone":"123-567-890"
}

In order to insert this document, you need to choose a collection where the document
will be stored. Here's how you can do it with the Mongo shell:
db.users.insert({"name": "francesco","age": 44, "phone": "123-567-
890"})

As for databases, collections can be created dynamically by specifying it into the


insert statement. Congratulations, you've just saved your first document!

MongoDB supports a special kind of collection named Capped


collections, which are fixed-size collections that are able to support
high-throughput operations where insert and retrieve documents
are based on insertion order. Capped collections need to be created
first before being able to use them. We will show you how to use
Capped collections in the next chapter, using the Java driver.

Querying documents
The find method is used to perform queries in MongoDB. If no argument is given to
the find method, it will return all the documents contained in the collection as in the
following statement:
> db.users.find()

The response will look something like this:


{ "_id" : ObjectId("5506d5988d7bd8471669e675"), "name" : "francesco",
"age" : 44, "phone" : "123-456-789" }

Maybe you have noticed that the _id field has been added to the document. This
is a special key that works like a primary key. As a matter of fact, every MongoDB
document requires a unique identifier and if you don't provide one in your
document, then a special MongoDB ID will be generated and added to the document
at that time.

[ 19 ]
Introduction to MongoDB

Now, let's include another user in our collections so that we can refine our searches:
> db.users.insert({"name": "owen","age": 32, "phone": "555-444-333"})

Your collection should now include two documents, as verified by the count function:
> db.users.count()
2

As you can see from the preceding insert command, document


keys are specified with quotes. This is not mandatory but generally
a good practice as it makes queries more readable.

Having two documents in our collection, we will learn how to add a query selector
to our find statement so that we filter users based on a key value. For example, here
is how to find a user whose name is owen:
> db.users.find({"name": "owen"})
{ "_id" : ObjectId("5506eea18d7bd8471669e676"), "name" : "owen",
"age" : 32, "phone" : "555-444-333" }

Multiple conditions can be specified within a query, just like you would do with a
WHERE – AND construct in SQL:

> db.users.find({"name": "owen", "age": 32})

{ "_id" : ObjectId("5506eea18d7bd8471669e676"), "name" : "owen",


"age" : 32, "phone" : "555-444-333" }

Choosing the keys to return


The queries mentioned earlier are equivalent to a SELECT * statement in SQL terms.
You can use a projection to select a subset of fields to return from each document
in a query result set. This can be especially useful when you are selecting large
documents, as it will reduce the costs of network latency and deserialization.

Projections are commonly activated by means of binary operators (0,1); the binary
operator 0 means that the key must not be included in the search whilst 1 obviously
means that the key has to be included. Here is an example of how to include the name
and age keys in the fields to be returned (along with the id field, which is always
included by default:
> db.users.find({}, {"name": 1,"age": 1})

[ 20 ]
Chapter 1

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


"age" : 44 }
{ "_id" : ObjectId("5506eea18d7bd8471669e676"), "name" : "owen", "age" :
32 }

By setting the projection values for the name and age to 0, the phone number is
returned instead:
> db.users.find({}, {"name": 0,"age": 0})
{ "_id" : ObjectId("5506d5988d7bd8471669e675"), "phone" : "123-456-789" }
{ "_id" : ObjectId("5506eea18d7bd8471669e676"), "phone" : "555-444-333" }

Note that you cannot have a mix of inclusions and exclusions


in your projection. The exception to the rule is the _id field. In
fact, {_id: 0, name: 1, age: 1} works but any inclusion/
exclusion combination of other fields does not.

Using ranges in your queries


Quite commonly, your queries will use some functions to restrict the range of the
returned data, which is done in most SQL dialects and languages with the > and <
or = operators.

The equivalent operators in MongoDB terms are $gt, $gte, $lt, and $lte. Here is
how to find users whose age is greater than 40 using the $gt operator:
> db.users.find({ age: { $gt: 40 } })

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


"age" : 44, "phone" : "123-456-789" }

The $gte operator, on the other hand, is able to select keys that are greater than or
equal (>=) to the one specified:
> db.users.find({ age: { $gte: 32 } })

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


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

The $lt and $lte operators, on the other hand, allow you to select keys which are
smaller and smaller/equal to the value specified.

[ 21 ]
Exploring the Variety of Random
Documents with Different Content
The text on this page is estimated to be only 28.22%
accurate

CHAPTER XIX. THE ROMANCE OF POTTERY — ENAMELING


EARTHENWABE INVENTED BY PALISSY. UT greater than the
achievements of merchants, princes, warriors and even statesmen,
are those of the great thinkers whose "thoughts do shake mankind";
of the great physicians who devote their lifetime to the cure of
disease and the alleviation of suffering; of the great discoverers who
call new worlds into activity and life; of the great inventors who, in
the teeth of discouragements innumerable, and difficulties
apparently insurmountable, have succeeded in wresting from nature
some of her most precious secrets, and conferred untold benefits on
mankind. Among the last class must ever be remembered with honor
the names of Bernard Palissy and John Bottgher, a brief account of
whose singularly interesting and romantic lives I now propose to
give. Bernard Palissy was born in the south of France in 1510. His
parents were too poor to give him any school education. "I had no
other books," said he afterwards, "than heaven and earth, which are
open to all." He learnt, however, the art of glass-painting, to which
he added that of drawing, and afterwards, reading and writing^
"When eighteen years old, the glass trade becoming decayed,
Palissy left his father's house with his wallet on his back, and went
out into the world to seek his fortune. For ten years he traveled over
Europe, until he married, 161
The text on this page is estimated to be only 28.81%
accurate

162 THE ROMANCE OF POTTERY. which put an end to his


wanderings; and he settled down to practice glass-painting and land-
measuring in the small town of Saintes. Three children were born to
him; and not only his responsibilities, but his expenses increased,
while, do what he could, his earnings remained too small for his
needs. It was therefore necessary for him to bestir himself. Though
only a glass-painter, he had an artistic soul, and the sight of an
elegant cup of Italian manufacture directed his mind to the art of the
enameling of earthenware. The sight of this cup disturbed his whole
existence; and from that moment the determination to discover the
enamel with which it was glazed possessed him like a passion. Had
he been a single man he might have traveled into Italy in search of
the secret; but he was bound to his wife and children, and could not
leave them; so he remained by their side, groping in the dark, in the
hope of finding out the process of making an enameling
earthenware. At first, he was utterly ignorant of pottery. He could
merely guess the materials of which the enamel was composed, and
he proceeded to try ALL MANNER OF EXPERIMENTS to ascertain
what these really were. He pounded all the substances which he
thought likely to produce it. Then he bought common earthen pots,
broke them into pieces, and spreading his compounds over them,
subjected them to the heat of a furnace which he erected for the
purpose of baking them. His experiments failed; and the results
were broken pots and a waste of fuel, drugs, time and labor, not to
speak of the opposition of his wife and friends who began to think
him mad. For many successive months and years Palissy pursued his
experiments. The first furnace having proved a failure, he proceeded
to erect another, out of doors. There he burnt more wood, spoiled
more drugs and pots, lost more time, until poverty stared him and
his family in the face. In the intervals of his experiments, he
occasionally worked at his former callings — painting on glass,
drawing portraits, and measuring land; but
The text on this page is estimated to be only 19.29%
accurate

PALISSY LEAVING HOME TO SEEK HIS FORTUNE.


The text on this page is estimated to be only 28.53%
accurate

ENAMELING EARTHENWARE. 165 his earnings from these


sources were very small. At length, because of the heavy cost of
fuel, he was no longer able to carry on his experiments in his own
furnace, but he bought more potsherds, broke them up as before
into three or four hundred pieces, and, covering them with
chemicals, carried them to a tile-work a league and a half from
Saintes, there to be baked in an ordinary furnace. After the
operation he went to see the pieces taken out; and, to his dismay,
the whole of the experiments were failures. But, though
disappointed, he was not yet defeated; for he determined on the
very spot to "begin afresh." His business as a land-measurer called
him away for a brief season from the pursuit of his experiments; but
he signalized his return by breaking three dozen new earthen pots,
the pieces of which he covered with different materials which he had
compounded, and then took them to a neighboring glass-furnace to
be baked. The results gave him a glimmer of hope. The greater heat
of the glass-furnace had melted some of the compounds; but though
Palissy searched diligently for the white enamel he could find none.
For two more years he went on experimenting without any
satisfactory result, until the proceeds of his land-surveying having
become nearly spent, he was again reduced to poverty. But he was
resolved to make one last great effort, and began by breaking more
pots than ever. Over THREE HUNDRED PIECES OF POTTERY covered
with his compounds were sent to the glass-furnace, and thither he
himself went to watch the results of the breaking. Four hours
passed, during which he watched, and then the furnace opened. The
material on one only of the three hundred pieces of potsherd had
melted, and it was taken out to cool. As it hardened, it grew white —
white and polished. The piece of potsherd was covered with white
enamel, described by Palissy as "singularly beautiful." He ran home
with it to his wife, feeling himself, as he expressed it, quite a new
creature. But the prize was not yet won — far from it. To complete
the invention he built a glass-furnace near his
The text on this page is estimated to be only 28.21%
accurate

166 THE ROMANCE OP POTTERY. dwelling, carrying the


bricks from the brick-yard upon his back. He was brick-layer, laborer,
and all. From seven to eight more months passed. . At last the
furnace was built and ready for use. Palissy had, in the meantime,
fashioned a number of vessels of clay in readiness for the laying on
of the enamel. After being subjected to a preliminary process of
baking, they were covered with the enamel compound, and again
placed in the furnace for the grand crucial experiment. Although his
means were nearly exhausted, Palissy had been for some time
accumulating a great store of fuel for the final effort, and he thought
it was enough. At last the fire was lit, and the operation proceeded.
All day he sat by the furnace, feeding it with fuel. He sat there
watching and feeding all through the long night. But the enamel did
not melt. The sun rose upon his labors. His wife brought him a
portion of the scanty morning meal — for he would not stir from the
furnace, into which he continued from time to time to heave more
fuel. The second day passed, and still the enamel did not melt. The
sun set, and another night passed. The pale, haggard, unshorn,
baffled yet not beaten Palissy sat by his furnace, eagerly looking for
the melting of the enamel. A third day and night passed — a fourth,
a fifth, and even a sixth — yes, for SIX LONG DAYS AND NIGHTS did
the unconquerable Palissy watch and toil, fighting against hope; and
still the enamel would not melt. It then occurred to him that there
might be some defect in the materials for the enamel — perhaps
something wanting in the flux; so he set to work to pound and
compound fresh materials for a new experiment. Thus two or three
more weeks passed. But how to buy more pots? His money was now
all spent; but he could borrow. His character was still good, and a
friend lent him enough to enable him to buy more fuel and more
pots. These he covered with the new compound, placed in the
furnace, and the fire was again lit. It was the last and most
satisfactory experiment of the whole. The fire blazed up;
The text on this page is estimated to be only 28.61%
accurate

ENAMELING EARTHENWARE. 167 the heat became intense


; but still the enamel did not melt. The fuel began to run short! How
to keep up the fire? There were the garden palings: these would
burn. So these were pulled up and cast into the furnace. They were
burnt in vain! The enamel had not yet melted. Ten minutes more
heat might do it. Fuel must be had at whatever cost. There
remained the household furniture and shelving. A crashing noise was
heard in the house; and amidst the screams of his wife and children,
who now really thought Palissy's reason was giving way, the tables
were seized, broken up and heaved into the furnace. The enamel
had not melted yet! There remained the shelving. Another noise of
the wrenching of timber was heard within the house, and the
shelves were torn down and hurled after the furniture into the fire.
Wife and children then rushed from the house, and went frantically
through the town, calling out that POOR PALISSY HAD GONE MAD,
and was breaking up his very furniture for firewood! For an entire
month his clothes had not been off his back, and he was utterly
worn out. He was, besides, in debt, and seemed on the verge of
ruin. But he had at length mastered the secret; for the last great
burst of heat had melted the enamel. The common, brown
household jars, when taken out of the furnace after it had become
cool, were found covered with a white glaze! For this, he could
endure reproach, contumely, and scorn, and wait patiently for the
opportunity of putting his discovery into practice as better days
came round. His next move was to hire a potter to make some
earthen vessels after the designs which he furnished; while he
himself proceeded to model some medallions in clay for the purpose
of enameling them. But how to maintain himself and family until the
wares were made and ready for sale? Fortunately there remained
one man in Saintes who still believed in him — an innkeeper, who
agreed to feed and lodge him for six months, while he went on with
his manufacture. As for the working potter
The text on this page is estimated to be only 28.86%
accurate

168 THE ROMANCE OF POTTERY. whom he had hired,


Palissy soon found that he could not pay him the stipulated wages.
Having already stripped his dwelling, HE COULD BUT STRIP
HIMSELF, and he accordingly parted with some of his clothes to the
potter, in part payment of the wages which he owed him. Palissy
then created an improved 'furnace, but he was so unfortunate as to
build part of the inside with flints. When it was heated these flints
cracked and burst, and the spiculae were scattered over the pieces
of pottery, sticking to them. Though the enamel came out right, the
work was irretrievably spoilt, and thus six months' more labor was
lost. Persons were found willing to buy the articles at a low price,
notwithstanding the injury they had sustained; but Palissy, inspired
by the spirit of a true artist, would not sell them, considering that to
have done so would be to " decry and abase his honor," and so he
broke in pieces the entire batch. At this stage of his affairs, he
became melancholy and almost hopeless, and seems to have all but
broken down. He wandered gloomily about the fields near Saintes,
his clothes hanging in tatters, and himself worn to a skeleton. In a
curious passage in his writings he describes how the calves of his
legs had disappeared, and were no longer able even with the aid of
garters to hold up his stockings, which fell about his heels when lie
walked. The family continued to reproach him for his recklessness,
and his neighbors cried shame upon him for his obstinate folly. So he
returned for a time to his former calling; and after about a year's
diligent labor, during which he earned bread for his household and
somewhat recovered his character among his neighbors, he again
resumed his darling enterprise. But though he had already searched
about ten years for the enamel, it cost him about eight more years
of experimental plodding before he perfected his invention. He
gradually learnt dexterity and certainty of result by experience,
gathering practical knowledge out of many failures. At last, after
about sixteen years' labor, Palissy took heart and called himself
potter. These sixteen years had been his
The text on this page is estimated to be only 28.45%
accurate

ENAMELIHG EARTHENWARE. 169 term of apprenticeship to


the art, during which he had wholly to teach himself, beginning at
the very beginning. He was now able to sell his wares and maintain
his family in comfort. But he never rested satisfied with what he had
accomplished. He proceeded from one step of improvement to
another, always aiming at the greatest perfection possible. He
studied natural objects for patterns, and with such success that the
great French naturalist, Buffon, spoke of him as "so great a
naturalist as nature only can produce." His ornamental pieces are
now regarded as rare gems in cabinets of virtuosi, and sell at almost
fabulous prices; a small dish twelve inches in diameter having been
sold some years ago for eight hundred and ten dollars. The
ornaments on them are for the most part accurate models from life,
of wild animals, lizards, and plants, found in the fields about Saintes,
and tastefully combined as ornaments into the texture of a plate or
vase. "When Palissy had reached the height of his art he styled
himself, "Ouvrier de Terre et Inventeur des Eustics Figulines."
The text on this page is estimated to be only 28.41%
accurate

CHAPTER XX. EXTRAORDINARY CAREER OF BOTTGHER,


THE INVENTOR OF HARD PORCELAIN. BOM, boys, do you admire
the more — Vanderbilt or Palissy ? the one striving for mere personal
aggrandizement; the other toiling and suffering for the general good
of humanity. One hundred years hence who will remember that such
men as Gould and Vanderbilt and Russell Sage ever existed, while
the name of Palissy will last as long as the fine art which he created?
And so with the illustrious John Frederick Bottgher, the inventor of
hard porcelain, whose life presents a remarkable contrast to that of
Palissy, though it also contains many points of romantic interest.
Bottgher was born at Schleiz, in the Voightland, in 1682, and at
twelve years of age was placed apprentice with an apothecary at
Berlin. He seems to have been early fascinated by chemistry, and
occupied much of his leisure in making experiments. These, for the
most part, tended in one direction — the art of converting common
metals into gold. At the end of several years, Bottgher pretended to
have discovered the universal solvent of the alchemists, and
professed that he had made gold by its means. The news spread
abroad that the apothecary's apprentice had discovered the grand
secret, and crowds collected about the shop to get a sight of the
wonderful young "gold-cook." The King himself expressed a wish to
see and converse with him, and 170
The text on this page is estimated to be only 28.38%
accurate

HARD PORCELAIN, ITS INVENTION. 171 when Frederick I.


was presented with a piece of gold alleged to have been converted
from copper, he was so dazzled with the prospect of securing an
infinite quantity of it, that he determined to secure Bottgher and
employ him to make gold for him within the strong fortress of
Spandan. But the young apothecary fled across the frontier into
Saxony. A REWARD OF A THOUSAND THALERS was offered for
Bottgher's apprehension, but in vain. He arrived at Wittenberg, and
appealed for protection to the Elector of Saxony, Frederick Augustus
I. (King of Poland), surnamed "The Strong/' Frederick being himself
very much in want of money at the time, was naturally overjoyed at
the prospect of obtaining gold in any quantity by the aid of the
young alchemist. Bottgher was accordingly conveyed in secret to
Dresden, accompanied by a royal escort. The Elector, however, must
needs leave him there for a time, having to depart forthwith to
Poland. But, impatient for gold, he wrote Bottgher from Warsaw,
urging him to communicate the secret, so that he himself might
practice the art of transmutation. The young "gold-cook," thus
pressed, forwarded to Frederick a small vial containing "a reddish
fluid," which, it was asserted, changed all metals, when in a molten
state, into gold. This important vial was taken in charge by the
Prince Fiirst von Fiirstenburg, who, accompanied by a regiment of
guards, hurried with it to Warsaw. Arrived there, it was determined
to make immediate trial of the process. The king and the prince
locked themselves up together in a secret chamber of the palace,
girt themselves about with leather aprons, and, like TRUE "GOLD-
COOKS," set to work melting copper in a crucible, applying to it
afterwards the red fluid of Bottgher. But the result was
unsatisfactory; for notwithstanding all that they could do, the copper
obstinately remained copper. On referring to the alchemist's
instructions, however, the king found that, to succeed with the
process, it was necessary that the fluid should be used " in great
The text on this page is estimated to be only 28.66%
accurate

172 HARD PORCELAIN, ITS INVENTION. purity of heart;*'


and as his majesty was conscious of having spent the evening in
very bad company, he attributed the failure of the experiment to that
cause. A second trial was followed by no better results, and then the
king became furious: for he had confessed and received absolution
before beginning the experiment. Frederick Augustus now resolved
on forcing Bottgher to disclose the golden secret, as the only means
of relief from his urgent pecuniary difficulties. The alchemist, hearing
of the royal intention, again determined to fly. He succeeded in
escaping his guard, and after three days' travel, arrived at Eus, in
Austria, where he thought himself safe. The agents of the Elector
were, however, at his heels. They had tracked him to the " Golden
Stag," which they surrounded, and seizing him in his bed,
notwithstanding his resistance and appeals to the Austrian
authorities for help, they carried him by force to Dresden. From this
place he was shortly after transferred to the strong fortress of
Koningstein. It was communicated to him that the royal exchequer
was completely empty, and that ten regiments of Poles were waiting
for his gold. THE KING HIMSELF VISITED HIM, and told him in a
severe tone that if he did not at once proceed to make gold, he
would be hung. Years passed, and still Bottgher made no gold; but
he was not hanged. It was reserved for him to make a far more
important discovery than the conversion of copper into gold, namely,
the conversion of clay into porcelain. Some rare specimens of this
ware had been brought from China by the Portuguese, which were
sold for more than their weight in gold. Bottgher was first induced to
turn his attention to the subject by Walter von Tschirnhaus, a maker
of optical instruments, also an alchemist. Tschirnhaus was a man of
education and distinction, and was held in high esteem by Prince
Fiirstenburg, as well as by the Elector. He very sensibly said to
Bottgher, still in fear of the gallows, "If you can't make gold, try and
do
The text on this page is estimated to be only 28.83%
accurate

HARD PORCELAIN, ITS INVENTION. 173 something else;


make porcelain. " The alchemist acted on the hint, and began his
experiments, working night and day. He prosecuted his
investigations for a long time with great assiduity, but without
success. At length some red clay, brought to him for the purpose of
making his crucibles, set him on the right track. He found that this
clay, when submitted to a high temperature, became vitrified and
retained its shape; and that its texture resembled that of porcelain,
excepting its color and opacity. He had, in fact, accidentally
discovered red porcelain, and he proceeded to manufacture and sell
it as porcelain. Bottgher was, however, well aware that the white
color was an essential property of true porcelain; and he therefore
prosecuted his experiments in the hope of discovering the secret.
Several years thus passed, but without success, until ACCIDENT
AGAIN STOOD HIS FRIEND, and helped him to a knowledge of the
art of making white porcelain. One day, in the year 1707, he found
his perruque unusually heavy, and asked of his valet the reason. The
answer was, that it was owing to the powder with which the wig was
dressed, which consisted of a kind of earth then much used for hair
powder. Bottgher's quick imagination immediately seized upon the
idea. This white earthy powder might possibly be the very earth of
which he was in search; at all events, the opportunity must not be
let slip of ascertaining what it really was. He was rewarded for his
painstaking care and watchfulness; for he found, on experiment,
that the principal ingredient of the hair-powder consisted of kaolin,
the want of which had so long formed an insuperable difficulty in the
way of his inquiries. The discovery, in Bottgher's intelligent hands,
led to great results, and proved of far greater importance than the
discovery of the philosopher's stone would have been. In October,
1707, he presented his first piece of porcelain to the Elector, who
was greatly pleased with it; and it was resolved that
The text on this page is estimated to be only 28.45%
accurate

174 HAED PORCELAIN, ITS INVENTION. Bottgher should


be furnished with the means for perfecting his invention. Having
obtained a skilled workman from Delft, he began to turn porcelain
with great success. He now entirely abandoned alchemy for pottery,
and inscribed over his door a distich, which, translated, reads thus:
"Almighty God, the great Creator, Has changed a goldmaker to a
potter." Bottgher^s further experiments with his new furnaces
proving very successful, and the porcelain which he manufactured
being found to fetch large prices, it was next determined to establish
a royal manufactory of porcelain. The manufacture of delf ware was
known to have greatly enriched Holland. Why should not the
manufacture of porcelain equally enrich the Elector? Accordingly, a
decree went forth, dated the twenty-third of January, 1710, for the
establishment of "a large manufactory of porcelain" at the
Albrechtsburg in Meissen. In this decree, which was translated into
Latin, French, and Dutch, and distributed by the ambassadors of the
Elector at all the European courts, Frederick Augustus set forth, that
to promote the welfare of Saxony, which had suffered much through
the Swedish invasion, he had "directed his attention to the
subterranean treasures" of the country, and, having employed some
able persons in the investigation, they had succeeded in
manufacturing "a sort of red vessel far superior to the Indian Terra
Sigillata"; as also "colored ware and plates, which may be cut,
ground and polished, and are quite equal to Indian vessels," and
finally that "specimens of white porcelain" had already been
obtained, and it was hoped that this quality, too, would soon be
manufactured in large quantities. The royal decree concluded by
inviting "foreign artists and handicraftsmen " to come to Saxony and
engage as assistants in the new factory, at high wages, and under
patronage of the king. For all his great services Bottgher was
wretchedly rewarded.
The text on this page is estimated to be only 28.59%
accurate

HARD PORCELAIN, ITS INVENTION". 175 Two royal officials


were put over his head as directors of the factory, while he himself
held the position of FOREMAN OF POTTERS ONLY, and at the same
time was detained the King's prisoner. During the erection of the
factory at Meissen, while his assistance was still indispensable, lie
was conducted by soldiers to and from Dresden; and even after the
works were finished he was locked up nightly in his room. All this
preyed upon his mind, and in repeated letters to the King he sought
to obtain mitigation of his fate. Some of these letters are very
touching. "I will devote my whole soul to the art of making
porcelain," he writes on one occasion; "I will do more than any
inventor ever did before; only GIVE ME LIBERTY, LIBERTY!" To these
appeals the King turned a deaf ear. He was ready to spend money
and grant favors; but liberty he would not give. He regarded
Bottgher as his slave. In this position the persecuted man kept on
working for some time, till, at the end of a year or two, he grew
negligent. Disgusted with the world and with himself, he took to
drinking. Such is the force of example that it no sooner became
known that Bottgher had betaken himself to this vice than the
greater number of the workmen at the Meissen factory became
drunkards too. Quarrels and fightings without end were the
consequence, and ultimately the whole of them, more than three
hundred, were shut up in the Albrechtsburg and treated as prisoners
of state. Bottgher at last fell seriously ill, and in May, 1713, his
dissolution was hourly expected. The King, alarmed at losing so
valuable a slave, now gave him permission to take carriage exercise
under a guard; and having somewhat recovered, he was allowed
occasionally to go to Dresden. In a letter written by the King in April,
1714, Bottgher was promised his full liberty; but the offer came too
late. BROKEN IN BODY AND MIND, alternately working and drinking,
though with occasional
The text on this page is estimated to be only 27.59%
accurate

176 HARD PORCELAIN, ITS INVENTION. gleams of nobler


intention, and suffering from constant illhealth, the result of his
enforced confinement, Bottgher lingered on for a few years more,
until death relieved him from his sufferings on the thirteenth of
March, 1719, in the thirty-fifth year of his age. He was buried at
night — as if he had been a dog — in the Johannis Cemetery at
Meissen; and such was the treatment, such the unhappy end, of one
of Saxony's greatest benefactors! •
The text on this page is estimated to be only 27.68%
accurate

CHAPTER XXI. MALIBRAN, THE GREAT SINGER —


TOUCHING STORY OF HER KINDNESS. HAVE now told you of great
merchants, bankers, inventors and what not, and thinking that
perhaps }ou might want a little change, I propose now to tell you of
a great artist who was also a great woman. Her name — perhaps
some of you know it — was Marie Felicita Garcia Malibran, and she
was one of the greatest singers that ever lived. She was born March
24, 1808; according to some authorities at Paris, and to others at
Turin. She was the daughter of Manuel Garcia, the celebrated
Spanish tenor singer, by whom she was instructed so thoroughly that
at the age of seventeen she made her public debut in London, March
25, 1826, in Rossini's opera "II Barbiere di Siviglia," and achieved an
instant triumph. She sang with success at public and private
concerts in different English cities, and in the autumn of that year
she came to New York as prima donna of an opera company, under
the direction of her father. The next year, on March 23d, she was
married to Eugene Malibran, an elderly French merchant of New
York ; but in .little more than a year financial difficulties brought
unhappiness, and the young wife left her old husband, and on
September 27, 1S27, she returned to Europe. On January 14, 1828,
she made her first appearance in Paris, repeating her English 177
The text on this page is estimated to be only 28.48%
accurate

178. MALIBRAX, THE GREAT SINGER. and American


successes. In 1835 the French courts pronounced her marriage with
M. Malibran to be void, and on March 29? 183G, she was married to
Charles de Beriot, the celebrated violinist. This marriage was a very
happy one, but, alas ! of short duration. A month after the marriage
she fell from her horse and was severely injured ; but making light
of the matter, she continued to perform in opera during the summer,
and in September, contrary to the advice of her physician, she
appeared in England, at the Manchester Musical Festival. A nervous
fever set in which soon proved fatal, and she died on September 23,
1836. A few years ago a handsome monument was erected in the
cemetery at Lacken, near Brussels, .over her remains, which had
been removed thither from their English resting place. Madame
Malibran's voice was a mezzo-soprano of great volume and purity,
and had been brought to absolute perfection by the severe training
of her father. Her private character was irreproachable. FEW WOMEX
HAVE BEEX MORE BELOVED for their amiability, generosity and
professional enthusiasm. Her intellect was of a high order, and the
charms of her conversation fascinated all who were admitted into
the circle of her intimate friends. Her benefactions amounted to such
considerable sums that her friends were frequently obliged to
interfere for the purpose of regulating her finances. The following is
one of the many touching stories of her kindness: In an humble
room in one of the poorest streets of London, Pierre, a faithful
French boy, sat humming by the bedside of his sick mother. There
was no bread in the closet, and for the whole day he had not tasted
food. Yet he sat humming to keep up his spirits. Still at times he
thought of his loneliness and hunger, and he could scarcely keep the
tears from his eyes; for he knew that nothing would be so grateful to
his poor invalid mother as a good, sweet orange, and yet he had not
a penny in the world. The little song he was singing was his own —
one he had composed, both air and words — for the child was a
genius.
The text on this page is estimated to be only 28.50%
accurate

A TOUCHING STOEY. 179 He went to the window, and


looking out saw a man putting up a great bill with yellow letters,
announcing that Madame Malibran would sing that night in public. "
Oh, if I could only go!" thought little Pierre; and then, pausing a
moment, he clasped his hands, his eyes lighted with a new hope.
Eunning to the little stand, he smoothed his yellow curls, and, taking
from a tiny box some old, stained paper, gave one eager glance at
his mother, who slept; and ran speedily from the house. "Who did
you say was waiting for me?" said the madame to her servant; "I am
already worn-out with company." "It's only a very pretty, little boy,
with yellow curls, who said if he can just see you he is sure you will
not be sorry, and he will not keep you a moment." "Oh, well, let him
come!" said the beautiful singer, with a smile; "I can never refuse
children." Little Pierre went in, his hat under his arm, and in his hand
a little roll of paper. WITH MANLINESS UNUSUAL FOR A CHILD, he
walked straight to the lady, and bowing, said, "I come to see you
because my mother is very sick, and we are too poor to get food
and medicine. I thought, perhaps, that if you would sing my little
song at some of your grand concerts, maybe some publisher would
buy it for a small sum, and so I could get food and medicine for my
mother." The beautiful woman arose from her seat. Very tall and
stately she was. She took the little roll from his hand and lightly
hummed the air. "Did you compose it?" she asked; "you, a child! And
the words? Would you like to come to my concert?" she asked. "Oh,
yes!" and the boy's eyes grew bright with happiness; "but I couldn't
leave my mother." "I will send somebody to take care of your mother
for the evening, and here is a crown with which you may go and get
food and medicine. Here is also one of my tickets. Come to-night;
that will admit you to a seat near me." Almost beside himself with
joy, Pierre bought some oranges, and many a little luxury besides,
and carried them home to the
The text on this page is estimated to be only 28.35%
accurate

180 MALIBRAN, THE GREAT SINGER. poor invalid, telling


her, not without tears, of his good fortune. When evening came, and
Pierre was admitted to the concerthall, he felt that never in his life
had he been in so great a place. The music, the myriad lights, the
beauty, the flashing of diamonds and rustling of silks, bewildered his
eyes and brain. At last she came, and the child sat with his glance
riveted on her glorious face. Could he believe that the grand lady, all
blazing with jewels, and whom everybody seemed to worship, would
really sing his little song? Breathless, he waited; the band — the
whole band — struck up a plaintive little melody. He knew it, and
clasped his hands for joy. And oh, how she sang it! It was so simple,
so mournful. Many a bright eye dimmed with tears, and naught
could be heard but the touching words of that little song — oh, so
touching! Pierre walked home as if he were moving on the air. What
cared he for money now? The greatest singer in all Europe had sung
his little song, and thousands had wept at his grief. The next day he
was frightened by a visit from Madame Malibran. She laid her hand
on his yellow curls, and turning to the sick woman, said, " Your little
boy, Madame, has brought you a fortune. I was offered, this
morning, by the best publisher in London, ONE THOUSAND FIVE
HUNDRED DOLLARS FOR HIS LITTLE SONG; and after he has
realized a certain amount from the sale, little Pierre here is to share
the profits. Madame, thank God that your son has a gift from
heaven." The noble-hearted singer and the poor woman Avept
together. As to Pierre, always mindful of Him who watches over the
tried and tempted, he knelt down by his mother's bedside and
uttered a simple prayer, asking God's blessing on the kind lady who
had deigned to notice their affliction. The memory of that prayer
made the singer more tender-hearted, and she who was the idol of
England's nobility, went about doing good. And in her early, happy
death, he who stood beside her bed and smoothed her pillow, and
lightened her last moments by his undying affection,
The text on this page is estimated to be only 19.50%
accurate

MADAME MALIBKAN, THE GREAT SLNOEB, VISITS LITTLE


PIEBBB.
The text on this page is estimated to be only 27.47%
accurate

A TOUCHING STOKY. 181 was little Pierre of former days,


now rich, accomplished and the most talented composer of the day.
For myself, I never did hear Malibran, though I have heard all the
great singers of the last twenty years: Mario, Giuglini, Tamberlik,
Keeves, Campanini, Tetjiens, lima de Murska, Gerster, Nilsson,
Materna, Foli, the Bettinis, Kellogg, Gary, Scalchi, Brignoli, Sinico,
Jenny Lind and Patti, with a host of others. I KEMEMBEE AS IF IT
WEEE YESTERDAY when I first heard Nilsson in opera. It was at the
Academy of Music, New York city; and if I remember rightly, in
"Faust," and so delighted was I that, on going home, I wrote the
following stanza in her praise, which the curious may find in
Scribner's Monthly for 1872 or '73 : TO CHEISTINE NILSSON. Winter
has come, the birds have fled; Their leaves the red-lipped roses
shed; But in thy crystal throat, Christine, Perpetual summer lurks
unseen; For sleeps therein, in shine or hail, The perfect-throated
nightingale; While on thy lips the roses lie That live when all their
sisters die.
The text on this page is estimated to be only 27.26%
accurate

CHAPTER XXII. A GREAT AMERICAN DOCTOR — DOCTOR


MARION SIMS. END for the doctor! " — how often one hears the cry,
and yet indispensable though the doctor is, he has had, and always
will have, his enemies. Eabelais, the witty Frenchman, sneered at
the entire profession, and that other famous countryman of his, Jean
Batiste Moliere, was constantly holding it up to ridicule. Indeed,
some of his first plays were satirical farces on the medical
profession. He once told Louis XIV., when speaking of his doctor, "
Sire, we talk together; he prescribes; I never take his physic, and
consequently I get well." On another occasion he defined a doctor as
"a man whom people pay to relate trifles in the sick room, until
either NATURE HAS CURED THE PATIENT w physic has killed him."
But Eabelais and Moliere lived many, many years ago, and Mie
science of medicine and surgery has vastly improved since ^,hen. In
their time it was only natural to laugh at doctors, who were nearly
all quacks, at one time believing that the only ind .infallible cure for
everything was water, with which they \iterally deluged the
unfortunate patient; and at another time putting their entire
confidence in bleeding. If, in the one case, the victim died, which he
generally did, it was because he had 182
The text on this page is estimated to be only 28.15%
accurate

A GREAT AMERICAN DOCTOR. 183 not swallowed sufficient


water; if in the other, because he had not lost enough blood. Of their
blood-letting propensities, so late even as the present century, many
writers have complained — some humorously, some bitterly. When
Tom Hood went to Germany, somewhere about the year 1836, he
was constantly suffering from violent spasms of the chest, coughing,
ague, and blood-spitting, and to crown all, the doctors proved
themselves leeches indeed. Like the rest of their countrymen, they
bled him so unmercifully that he grew weak and thin. "I heard the
other day," he writes, " of a man who had no fewer than fifty-five
leeches on him. The man who bled me, and there are several
bleeders here, told me he had attended eighty patients that month!
One of THE BLISTERS WOULD DRAW A WAGON." But, as I have
said, these days are past. Surgery, at any rate, has been raised to
the dignity of a science, and even medicine is slowly struggling
through its empirical stage. The ideal modern physician is
everybody's friend, and however we mayu regret being obliged to
send for him, when he does come, no visitor is more welcome. And
the great man of whom I am going to speak was in very truth and
deed a model, an ideal physician. If the story of one thousandth part
of the good he did — secretly, and not letting even his right hand
know what his left hand did — were published, it would fill many
volumes. When I look back to the days in which I knew him; recall
his kindly face; his bright, beaming eye; his gentle, reassuring smile;
his courtly ease and womanly delicacy — when, I say, I remember
these things, and all he did for me and mine, it is hard to keep back
the tears that will press forward in regretful memory of Dr. Marion
Sims. Yes, that was his name; the name of the most famous
American surgeon, in his way, that ever lived; a scientist who will
always rank among the foremost men of his age; and one whose
death on November 13, 1883, created a profound feeling of sorrow
and regret all over the civilized globe. This great man, as I have
said, was Dr. James
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