Using MongoDB to Implement Textbook Management System instead of MySQL
Zhu Wei-ping
Computer and Engineering Department, CDA VTC
Chengdu China email:zwp_
Chen Huan
YiBin Vocational and Technical College
YiBin China
email:
Li Ming-xin
Computer and Engineering Department, CDA VTC
Chengdu China税前工资怎么算
email:
Abstract: With the development of internet Web2.0 technology,
the traditio n al relatio n al databa is widely ud i n
in formation man agemen t system. However, it is n ot effective, when we need to query a wide range of massive data, especially with multi-table join queries. Now, a kin d of n ew techn ology emerged----NoSQL, which is n o n -relatio n al databa man agemen t system with format loo data storage, n ot support the join operation , the effective query capability etc advan tages. This paper attempts to u NoSQL databa to replace the relatio n
al databa, applied to traditio n
al in formation man agemen t systems, compare the two databa technologies, give the key code of NoSQL implementation, and finally list the performance comparison of two schemes.
Keywords : MongoDB;MySQL; RDBMS; NoSQL
I. I NTRODUCTION Traditional relational databa u two-dimensional table
to reprent data, with strict consistency of databa transactions, real-time to read and write, can implement complex SQL queries, especially multi-table related query. However, for a wide range of massive data queries, multi-table query is not effective. NoSQL is not a relational
databa management system. This system us a
non-relational model of data structure. Usually it d oes’t support the join operation, while the query is efficiency. This paper attempts to u this new databa technology in the
textbooks management system, to implement
high-performance data queries. In this paper, the relational databa using MySQL. As the most popular open source
databa in the world, MySQL has the following features:
small, fast, low cost [1]. NoSQL databa system u MongoDB, which is document oriented and characterized by mass data storage, at the same time with good query
performance [2].
Section II of the paper we introduce the concepts of non-relational databa and the characteristics of MongoDB. The implementation of textbooks management system bad on MongoDB will be described in ction III. The fourth ction we compare the performance of textbooks management system bad on MySQL and MongoDB. In the
fifth part, we point out some drawbacks of the NoSQL implementation and future work to do. II.
NON-RELATIONAL DATABASE AND M ONGO DB
NoSQL means non-relational databa. The data structure of non-relational databa is not fixed. There are key (key-value) storage type, document storage type and so on. MongoDB is a document oriented databa. It’s schema-free, which contains Databa, C ollection, and Document. One Databa can have multiple C ollections. Each Collection is a collection of Documents. The structure of MongoDB system is displayed in Figure 1. C ollection can be created at any time, without predefin
ed. It can also contains records with different schema documents, which means one record of a document has 3 attributes, and the
next record in the document may has 10 attributes. The type
of the property can be any basic data types, such as numbers, strings, dates, etc, or an array or hash, and even a sub-document. This can realize de-normalized data model and improve query speed [3]. The textbooks management system which is bad on MongoDB will be ud in this
data model.
Figure 1 MongoDB document-oriented databa III. I MPLEMENTATION S CHEME A. Textbooks Management System Data Model a) Traditional relational data model The system u traditional data model is bad on MySQL that mainly contain students, teachers, textbooks, ___________________________________ 978-1-61284-486-2/11/$26.00 ©2011 IEEE
vis系统subscriptions textbook, textbook u, textbook storage, entry textbook, delivery textbook, and other entities. Students associate with Class and Departments by foreign key. The E-R data model of the system is shown in Figure 2, displaying that deptC ode is one to many relationship with the teach
erInfo, textBook and teacherInfo is many to many relationship. If you want to query a certain teacher's department and using his/her textbooks of information, you need to associate deptC ode, teacherInfo, teaUSEbook and textBook four tables. Associated with multi-table query, you have to spend lots of time. To solve this problem, in this paper we attempt to u NoSQL to solve it.
Figure 2 part of the relational data model of the system
b) NoSQL data model
Scheme free is one of the characteristics of NoSQL.According to system’s requirements; two basic information, students’ and teachers’ information will be created in MongoDB. Subscription textbooks, ud textbooks, textbooks storage, entry textbook, delivery textbook, can be t into the basic information of teacher with embedded documents in the C ollection. But considering too many embedded documents are resulted in increasing size of one single document, we create a parate textbooks operating Collection, which is shown
in Figure 3:
Figure 3 part of the system’s data model bad on MongoDB
B.System Implementation
In this system, using Java language to develop system,
access and operate the databa needs the driver that
provided by MongoDB. The key step to fulfill as the
following, first, using Java program to connect the databa,
and then inrt the data, finally, get the results ts by query
condition.
a) Establish a connection
In order to make Java programs connect with MongoDB
databa, you need to install the drivers and t the
environment variables. Then import the development kit of
MongoDB in the application program. After that you can
easily connect to MongoDB databa, the following are the
key codes:
Mongo m = new Mongo ("DBrver", 27017); // connect
databa with the databa rver name and port number
DB db= m.getDB("dbname"); //open databa
b) Inrt the data
In the traditional JDBC development, Java program
establish the connection with databa firstly, then pass the
SQL statements to program, at last inrt the data into the
databa, which is process-oriented thinking. it is not benefit
to program design and system maintenance. MongoDB
databa u object-oriented thinking to implement system,
first, according "textbook" to create a DBCollection object
coll, and then create a BasicDBObject object doc, add
textbooks information to the object doc , and finally add the爷爷的情人
object doc to the object coll , at last inrt data into
MonoDB databa.
DBCollection coll = db.getCollection("textbook");
流行词
BasicDBObject doc = new BasicDBObject();
doc.put("bookisbn", "9787561829318");
机要秘书doc.put("bookname", " Oracle databa Tutorial ");
doc.put("bookpress", " Tianjin University Press");
coll.inrt(doc);
c) Query the data
1) Query a document. U DBObject to indicate query
conditions, or u nested multilayer to reprent complex
conditions, then it will return results for object of DBObject.
Query data in MongoDB databa follow object-oriented
thinking too. To create DBC ollection object coll for
determining the scope of the query by getting C ollection
“textbooks” in the databa. Later create BasicDBObject
object cond, and write the query condition into cond, finally
put the object cond into the method findOne of the object
coll, the query results return to DBObject object ret.
DBCollection coll = db.getCollection("textbook");
BasicDBObject cond = new BasicDBObject(); // Query
matching conditions
cond.put("bookisbn", "9787561829318");
DBObject ret = coll.findOne(cond);
2) Query document collection, u DBCursor return a result
t.
The following steps are the same as above mentioned.
Put the object cond into the method find of the object coll,
the query results back to a cursor (DBC ursor) object ret,
which contains a t of objects DBObject. You can u the
loop statement to process the data one by one.
cond.put("bookprice", new BasicDBObject("$gt", 50));
// Price is greater than 50
DBCursor ret = coll.find(cond);
while (ret.hasNext()) {
//data processing ret.Next();亚洲伦理小说
}
Above steps are the key to the implementation for the system. C omparing to using JDBC, MySQL s
olution, the system adopts the object-oriented method to implement, developers can easily develop and maintain. The following ction will display the efficiency of two different implement methods.
小王子童话故事IV.P ERFORMANCE C OMPARISON
In the performance testing, enter 100,000 textbooks information data into databa. The cost time of MongoDB and MySQL were recorded as shown in figure 4. The left columns show the average time cost for inrting 100,000 textbooks information. The right columns show the average time cost for querying 2,000 records from 100,000 textbooks records .In order to facilitate the graphical display, t original data multiply C oefficient for 100. In the performance of inrting data, MongoDB spends less times than MySQL, which testified it is improving query efficiency.
Figure 4 MySQL and MongoDB inrt, query time
V.C ONCLUSION
The system is developed bad on MongoDB 1.6, which
is compare to MySQL implement scheme, inrting and querying data by MongoDB. It has obvious advantages. However, in the development process also encountered the references of MongoDB which is less than MySQL. We have to spend much more time on problem-solving.and
post-maintenance issues is not easier than MySQL. But the development of MongoDB in the application system will continue to rearch.
R EFERENCES
[1]MySQL databa development history
/shujukujishu/2665.html
[2] A discussion of NoSQL databa - why should non-relational
databa [OL]/blog/524977
[3]Pan Fan, From MySQL to MongoDB – Visual China’s R oad
of NoSQL China [J], Programmer, 201006, 79-81
[4]Huang Xian-li, NoSQL non-relational databa development
and application[J], Fujian PC, 201007,30,45
[5]Zhong Wang-wei, Huang Xiao-ou, Bad on C / S and B / S
mixed-mode library management system [J], Modern
computer, 200708,124-126
[6]Bruce Eckel,Thinking in Java(Second Edition)[M],
Machinery Industry Press, 2002
[7]C harles A.Bell,In-depth understanding of MySQL [M],
Posts & Telecom Press, 2010
[8]Nicholas .Zakas,JavaScript Advanced Programming
˄Second Edition˅[M], Posts & Telecom Press, 2010
[9]Brett McLaughlin, JavaϢXML˄Photocopy Edition˅[M],
Southeast University Press, 2007
[10]Lauriat.S.M.,Ajax Architecture and Best Practices in depth
为了幸福[M],Posts & Telecom Press,2009