MongoDB and Blockchain – Storing and Retrieving Data with Hash

blockchainipfsprivate-blockchainstorageswarm

Blockchain can not store and shall not be used to store all the data of users. There are 2 reasons for that –

1) To store data in blockchain requires gas price (transaction cost)

2) Since all blocks are replicated on all the nodes participating in blockchain there are some limitations for storing big data in blockchain.

Blockchain is not replacement of a database but it is another layer on top of that to store transactions which are crucial for business and to ensure trust among multiple entities.

I read that remaining data shall be stored in IPFS and hash of that data is stored in blockchain. But as IPFS only supports unstructured data i.e. images and videos.

I want to store remaining user data in MongoDB and I will store hash of MongoDB document in blockchain. I shall be able to retrieve data stored in document from hash that is stored in blockchain. Are there any resources or tutorials available for implementing the same?

Best Answer

I recently build a tool to store, index and search content on IPFS called IPFS-Store and I'm using my tool to store and index JSON document (MongoDB style) but you an use it to index any type of content.

The service expose a REST API which accept any type of content, so you can basically push and pull JSON document.

For instance

curl -X POST \
  http://localhost:8040/ipfs-store/store \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'file={"attribute1": "my json file to store on IPFS", "attribute2": "val2", "attribute3": 10}'

I'm planning to provide support for SWARM in the future.

Related Topic