Michael Hunziker
Michael Hunziker

Reputation: 2679

Get referenced XML data into mongodb

I would like to get the following xml data into mongodb. As a result I would like to have 4 mongodb collections (a,b,c,d). Note that e.g. the xml-element "store" is linked to the xml-element "book1" and "book2".

<?xml version="1.0" encoding="UTF-8"?>
  <bookstores>
    <books>
      <book>
        <id>book1</id>
        <name>The Da Vinci Code</name>
      </b>
      <book>
        <id>book2</id>
        <name>Brave New World</name>
      </book>
    </books>
    <store>
      <id>store1</id>
      <book ref="book1"/>
      <book ref="book2"/>
    </store>
  </bookstores>

Does anyone have a clue on how to store this data in an intelligent nosql-kind-of-way? I'm not really sure how to actually get the xml transformed into mongodb...

Thank you very much for your help!

Cheers Michael

Upvotes: 0

Views: 186

Answers (1)

Aravind Yarram
Aravind Yarram

Reputation: 80196

Seems like you are kind of managing relationships. Inferred from your below statement

Note that e.g. the xml-element "c" has a reference to the xml-element "b1".

Graph databases are good for this. Look at Neo4j. If you want an answer specific to mongodb then update your question with meaningful data rather than using "a", "b" as the data values.


EDIT #1

My initial suggestion is to use 1 collection (db) per store and have all the books of that particular store as individual documents within that collection. Most of the storage model decisions in NoSQL space are influenced by the data access mechanisms i.e. how you intend to use the data (this is sometimes also known as pre-joined data). So provide that information as well.

Upvotes: 2

Related Questions