Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
MongoDB_Tokyo_2012-NRI_OpenStandia
1. MongoDB Tokyo 2012
Nomura Research Institute
OpenStandia
Shoken Fujisaki
Dec. 12, 2012
1
2. About me
• Shoken Fujisaki (@syokenz)
• syokenz@gmail.com
• Technical Engineer
• Leader of Marunouchi MongoDB
http://syokenz.github.com/marunouchi-mongodb
• Write a series of MongoDB articles in gihyo.jp
http://gihyo.jp/dev/serial/01/mongodb
2
3. About company
• Nomura Research Institute ( NRI )
• 野村総合研究所
• System Integrator
• Department : Open Source Solution Department
• Team: OpenStandia http://openstandia.jp
• Mission:
• System development using OSS
• Support for OSS
• MongoDB (In preparation. contact : ossc@nri.co.jp)
• Assigned: Research and Development for OSS
3
4. Agenda
1.Meetup MongoDB in Marunouchi Tokyo
2.XML Search App on MongoDB
3.Hybrid MySQL and MongoDB
4.Summary
4
5. Agenda
1.Meetup MongoDB in Marunouchi Tokyo
2.XML Search App on MongoDB
3.Hybrid MySQL and MongoDB
4.Summary
5
6. Meetup MongoDB in Marunouchi Tokyo
• Site : http://syokenz.github.com/marunouchi-mongodb
• “Marunouchi” is near Tokyo Station. marunouchi mongodb
• Held once a month.
• Done four times, next fifth on Dec 18.
• Features of this meetup
• Free
• Hands-On
• Open old documents and source code in Github.
http://github.com/syokenz/marunouchi-mongodb
6
7. Meetup MongoDB in Marunouchi Tokyo
• Theme #1 - #5
• #1. Learn a query on MongoDB compared to SQL
• #2. Sharding on each participant’s PC.
• #3. “v2.2 new futures” and “Replica Sets hands-on”
• #4. “Make sample app using REST I/F” and “Configuration File Options”
• #5. “Source code reading”, “Custom building” and “Operation Tips”
Next
• Future Dec 18
• GridFS, Geo-indexing, Performance tuning, etc…
7
8. Articles in Web
• Writie a series of MongoDB in gihyo.jp.
• gihyo.jp is website of 技術評論社.
• http://gihyo.jp/dev/serial/01/mongodb
• This article is output of Meetup Marunouchi MongoDB.
8
9. Agenda
1.Meetup MongoDB in Marunouchi Tokyo
2.XML Search App on MongoDB
3.Hybrid MySQL and MongoDB
4.Summary
9
10. XML Search App on MongoDB
• Purpose
• Learning “When should we consider using MongoDB?”
• Existing Problem
• How do we store XML to DB?
• Solution
• Schema-less
10
11. XML Sample Data
CD BOOK PC
<?xml version="1.0" encoding=“UTF-8" ?> <?xml version="1.0" encoding=“UTF-8" ?> <?xml version="1.0" encoding=“UTF-8" ?>
<items> <items> <items>
<category>music cd</category> <category>book</category> <category>pc</category>
<title>jazz collection</ title > <title>guide of mongodb</ title > <name>let’s book air</ name>
<stock>10</stock> <stock>10</stock> <stock>10</stock>
<price>1000</price> <price>1200</price> <price>120000</price>
<artist>nomura band</artist> <ISBN>4797327421</ISBN> <software>
</items> <publish> <os>windows 7 pro</os>
<company>nomura pub</company> <option>Office 2010</option>
search conditions <url>http://nomura.pub</url> </software>
ex. <address>….</address> <hardware>
select count(*) from items </publish> <cpu>Intell core i 7</cpu>
where stock > 10 </items> ….
</items>
• Each XML schema is different.
• If add “FOOD category” CD BOOK PC FOOD
• In RDB, Create FOOD table?
• => It takes a lot of cost and not scale out.
• RDB is not good extending the Schema.
11
12. XML Sample Data
CD BOOK PC
<?xml version="1.0" encoding=“UTF-8" ?> <?xml version="1.0" encoding=“UTF-8" ?> <?xml version="1.0" encoding=“UTF-8" ?>
<items> <items> <items>
<category>music cd</category> <category>book</category> <category>pc</category>
<title>jazz collection</ title > <title>guide of mongodb</ title > <name>let’s book air</ name>
<stock>10</stock> <stock>10</stock> <stock>10</stock>
<price>1000</price> <price>1200</price> <price>120000</price>
<artist>nomura band</artist> <ISBN>4797327421</ISBN> <software>
</items> <publish> <os>windows 7 pro</os>
<company>nomura pub</company> <option>Office 2010</option>
search conditions <url>http://nomura.pub</url> </software>
ex. <address>….</address> <hardware>
select count(*) from items </publish> <cpu>Intell core i 7</cpu>
where stock > 10 </items> ….
</items>
• MongoDB is Schema-less.
• MongoDB can save any XML Data in one collection.
• Search on any element.
ex. db.items.find( {‚stock‛: {$gt: 10} } ); // where stock > 10
db.items.find( {‚title‛: /^jazz/ } ); // where title like ‘jazz%’
• Scalable
12
13. Architecture
Search by Web browser. WebUI
(Node.js)
Insert multi type XML data
into MongoDB by batch.
XML type1
XML type2
XML type3
MongoDB
13
15. Insert multi type XML
The code to insert the multi
type XML data to MongoDB
is 10 lines !
15
16. Agenda
1.Meetup MongoDB in Marunouchi Tokyo
2.XML Search App on MongoDB
3.Hybrid MySQL and MongoDB
4.Summary
16
17. Hybrid MySQL and MongoDB
• Use case in NRI
• Working SNS Service for financial business since
Apr.2012
• MySQL (and Java)
SNS Service
MySQL
17
18. Hybrid MySQL and MongoDB
• Use case in NRI
• Working SNS Service for financial business since
Apr.2012
• MySQL (and Java)
• Add CRM system with MongoDB
SNS Service
CRM
MySQL MongoDB
18
19. Extended fields for each user on MongoDB
• Requirements
• Defines extended fields BY user.
• Extended fields type is text, list or check box.
• Search with extended fields. Customers
SNS Service Search
salses_level = 3
Customer Fields
-name
CRM -email
Customer Fields
User A -address
-name -sales_level
-email -industry
-address -…
MySQL MongoDB
User B -interests
-assets Extended fields
-… depents on the user
19
20. Schema Design
MongoDB
CRM
extended_definition extended_values
collection collection
user
user
collection
user
collection
collection
20
21. Schema Design
MongoDB
CRM
extended_definition extended_values
collection collection
user
user
collection
user
collection
collection
21
23. Agenda
1.Meetup MongoDB in Marunouchi Tokyo
2.XML Search App on MongoDB
3.Hybrid MySQL and MongoDB
4.Summary
23
24. Summary
• MongoDB can meet various kinds of customer
requirements, especially for large system.
• Schema-less
• Search like SQL
• Scalable
• We can add MongoDB to the system using
MySQL.
• Hybrid MySQL and MongoDB
• Select database depending on the data
characteristic
24
25. All product names mentioned are trademarks or
registered trademarks of the respective companies.
Thank You
ossc@nri.co.jp http://openstandia.jp/
25