I am getting the actions log data using an action constructor in a smart contract. I need to save this data in MongoDB from the smart contract. How can I do this? I didn't get exactly my required solution. How do I use MongoDB in eosio smart contracts? Any help would be appreciated. I am using Ubuntu 18.04 LTS on Windows 10.
1 Answer
You can't access mongodb from smart contract at all. It is executed in closed and segregated context and can't communicate with external network except for internal state. Internal state here means data stored by eosio::multi_index.
Once transaction is recorded, you can make a monitoring daemon to read it from block and do something for your demand like saving data into mongodb.
-
Hi..thanx for the answer. Monitoring daemon to read means accessing smart contract related data through API like eos-sharp or eosjs. right?– VarshApr 22, 2020 at 2:14
-
-
Hey @conr2d, If I want to save eos transaction data to MongoDB using web API, do I need to install MongoDB externally or connecting internally with EOS is possible?– VarshFeb 8, 2021 at 10:52
-
@Varsh The feature you describe is supported by deprecated mongo_db_plugin. You can try using it (I think it still works), but you may need to build nodeos including mongo_db_plugin by yourself. You could write fill-mongodb plugin for history-tools which is an external daemon but fills mongodb with tx data, but it would require knowledge for writing plugin in c++.– conr2dFeb 8, 2021 at 19:55
-
can you please look into my questions eosio.stackexchange.com/questions/6282/save-blocks-into-mongodb and eosio.stackexchange.com/questions/6281/… ?– VarshJul 12, 2022 at 2:25