• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Document types handled by MongoDB

 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Does MongoDB store only JSON document type? Is it not possible to store Document types such as MS Word, Image, video or XML files in MongoDB?

Regards,
Rajesh
 
amit punekar
Ranch Hand
Posts: 544
 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit
 
Rajesh So
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a JSON document, I can notice that its possible to write a query such as this


The reason is that the developer of the query understands that there is a key called 'by' and there are chances of some documents having value as 'coderanch'.

If I upload a non-JSON document, say a MS Word document, and it has a key called 'by' and a value as 'coderanch', the query would miss the key/value pair.

Am I right with the understanding that although MongoDB permits non-JSON document, the MongoDB is best useful for JSON documents ?

 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are getting confused over the word "document".

  • A MongoDB "document" is analogous to a "record" in a relational database table. It is formatted like JSON although the actual storage format is BSON as described here: JSON and BSON
  • A MongoDB "collection" is analogous to a relational database table i.e. it contains a lot of JSON documents.

  • It is true that MongoDB also allows you to store data in other formats e.g. using GridFS, but GridFS stores this data separately from your JSON collections. This is like BLOB storage in relational databases i.e. MongoDB doesn't know or care what's inside your files as it treats them simply as binary objects - so the file could contain image data, XML or indeed Microsoft Office data.

    So, when you talk about storing Microsoft Word "documents" in MongoDB via GridFS, what you are really talking about is storing Word files as BLOBs (actually a set of BLOB chunks). MongoDB does not see these files as JSON documents, because they are not stored as JSON documents. You should probably read through the MongoDB documentation on GridFS to get a better understanding of what it does.

    Finally, there is a "bindata" type that can be used for storing small volumes of binary data in-line within a JSON document, but I'm not sure when/how you would use this, and the binary data would still be a "black box" from MongoDB's perspective. Also, there is a size limit of 16MB for any JSON document stored within a MongoDB collection, so your binary data would have to be smaller than this limit.
     
    Rajesh So
    Ranch Hand
    Posts: 149
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Chris,
    I understand now. You are right that I was confused that Document based data bases meant any document. Thanks for correcting.
    Thanks,
    Rajesh
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic