MongoDB For Java Developers Design Build and Deliver Efficient Java Applications Using The Most Advanced NoSQL Database Francesco PDF Download
MongoDB For Java Developers Design Build and Deliver Efficient Java Applications Using The Most Advanced NoSQL Database Francesco PDF Download
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...
https://ebookname.com/product/oracle-database-programming-using-
java-and-web-services-1st-edition-kuassi-mensah/
https://ebookname.com/product/learn-objective-c-for-java-
developers-1st-edition-james-bucanek/
https://ebookname.com/product/professional-eclipse-3-for-java-
developers-1st-edition-berthold-daum/
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/
https://ebookname.com/product/key-buildings-from-prehistory-to-
the-present-plans-sections-and-elevations-andrew-ballantyne/
https://ebookname.com/product/lectures-on-the-history-of-moral-
and-political-philosophy-jonathan-wolff/
https://ebookname.com/product/essentials-of-foreign-exchange-
trading-essentials-series-1st-edition-james-chen/
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
Francesco Marchioni
BIRMINGHAM - MUMBAI
MongoDB for Java Developers
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.
ISBN 978-1-78528-027-6
www.packtpub.com
Credits
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
Technical Editor
Bharat Patil
Copy Editors
Merilyn Pereira
Laxmi Subramanian
About the Author
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).
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.
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.
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.
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
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ 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.
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.
[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.
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."
[ 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");
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 ".
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.
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.
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.
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.
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:
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).
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).
[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:
[4]
Chapter 1
The following is a table that contains the advantages and disadvantages of NoSQL
databases:
[5]
Introduction to MongoDB
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.
On the other hand, operations that includes multiple documents (often referred to as
multi-document transactions), are conversely not atomic.
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
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:
[7]
Introduction to MongoDB
• 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.
[8]
Chapter 1
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
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
• 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
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
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
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
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.
[ 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.
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:
[ 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
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.
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
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"})
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()
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
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:
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
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" }
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 } })
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 } })
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
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.
ebookname.com