bcskill-eosio-mongodb-queries v1.0.1
EOSIO MongoDB Queries
Quickly and easily create complex MongoDB Queries for the EOSIO blockchain.
Install
npm
$ yarn add eosio-mongodb-queriesweb
<script src="https://wzrd.in/standalone/eosio-mongodb-queries@latest"></script>Quickstart
import { MongoClient } from "mongodb";
import { getAccount } from "eosio-mongodb-queries";
(async () => {
const client = await MongoClient.connect("mongodb://localhost:27017", { useNewUrlParser: true });
// Optional Parameters
const options = {
gte_block_num: 0,
lte_block_num: Infinity,
};
const result = await getAccount(client, "eosnationftw", options);
// {
// name: 'eosnationftw',
// block_num: 6101090,
// stake_quantity: 2.8,
// stake_net_quantity: 0.4,
// stake_cpu_quantity: 2.4
// }
})();EOSIO Full Node
You must first enable the MongoDB plugin to your EOSIO full node by including the following to your configuration.
config.in
# Override default maximum ABI serialization time allowed in ms (eosio::chain_plugin)
abi-serializer-max-time-ms = 5000
# Plugin(s) to enable, may be specified multiple times
plugin = eosio::mongo_db_plugin
# MongoDB URI connection string, see: https://docs.mongodb.com/master/reference/connection-string/. If not specified then plugin is disabled. Default database 'EOS' is used if not specified in URI. Example: mongodb://127.0.0.1:27017/EOS (eosio::mongo_db_plugin)
mongodb-uri = mongodb://localhost:27017Replay Blocks
To allow actions to be decoded from the ABI, you must replay all blocks from the genesis.
$ nodeos --replay-blockchain --hard-replay-blockchain --mongodb-wipeQuery Ideas
- Vote Tally for
eosio.forum(submitted by Denis from EOS Nation) - Block Producer votes & positions (submitted by Nathan from GenerEOS)
- Name auction for all-time bids or current bid (submitted by Syed from EOS Cafe)
References
MongoDB Pipeline
- https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/
- https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/
Contributors
This is made with ♥ by:
- EOS Nation (
eosnationftw)
Voting on the EOSIO mainnet helps build more awesome tools for the EOS community.
API
Table of Contents
getActions
EOSIO MongoDB Actions
Parameters
clientMongoClient MongoDB ClientoptionsObject Optional Parameters (optional, default{})options.account(string | Array<string>)? Filter by account contracts (eg: "eosio","eosio.token")options.name(string | Array<string>)? Filter by action names (eg: "undelegatebw", "delegatebw")options.limitnumber Limit the maximum amount of of actions returned (optional, default25)options.skipnumber? Skips number of documentsoptions.sortobject? Sort by ascending order (1) or descending order (-1) (eg: {block_num: -1})options.matchobject? Match by entries using MongoDB's $match (eg: {"data.from": "eosio"})options.trx_idstring? Filter by exact Transaction Idoptions.irreversibleboolean? Irreversible transaction (eg: true/false)options.block_numnumber? Filter by exact Reference Block Numberoptions.block_idstring? Filter by exact Reference Block IDoptions.lte_block_numnumber? Filter by Less-than or equal (<=) the Reference Block Numberoptions.gte_block_numnumber? Filter by Greater-than or equal (>=) the Reference Block Number
Examples
const options = {
account: "eosio",
name: ["delegatebw", "undelegatebw"],
match: {"data.from": "eosnationftw", "data.receiver": "eosnationftw"},
irreversible: true,
sort: {block_num: -1}
};
const results = await getActions(client, options);
console.log(await results.toArray());Returns AggregationCursor<Actions> MongoDB Aggregation Cursor
getBlocks
EOSIO MongoDB Blocks
Parameters
clientMongoClient MongoDB ClientoptionsObject Optional Parameters (optional, default{})options.limitnumber Limit the maximum amount of of actions returned (optional, default25)options.skipnumber? Skips number of documentsoptions.sortobject? Sort by ascending order (1) or descending order (-1) (eg: {block_num: -1})options.matchobject? Match by entries (eg: {"block.producer": "eosio"})options.block_numnumber? Filter by exact Reference Block Numberoptions.block_idstring? Filter by exact Reference Block IDoptions.lte_block_numnumber? Filter by Less-than or equal (<=) the Reference Block Numberoptions.gte_block_numnumber? Filter by Greater-than or equal (>=) the Reference Block Number
Examples
const options = {
match: {"block.producer": "eosnationftw"},
sort: {block_num: -1}
};
const results = await getBlocks(client, options);
console.log(await results.toArray());Returns AggregationCursor<Blocks> MongoDB Aggregation Cursor
getAccountControls
EOSIO MongoDB Account Controls
Parameters
clientMongoClient MongoDB ClientoptionsObject Optional Parameters (optional, default{})options.limitnumber Limit the maximum amount of of actions returned (optional, default25)options.sortobject? Sort by ascending order (1) or descending order (-1) (eg: {controlled_account: -1})options.skipnumber? Skips number of documentsoptions.matchobject? Match by entries (eg: {controlled_account: "eosio.saving"})
Examples
const options = {
match: {controlled_account: "eosio.saving"},
};
const results = await getAccounControls(client, options);
console.log(await results.toArray());Returns AggregationCursor<AccountControls> MongoDB Aggregation Cursor
setDefaultLimit
Set default limit
Parameters
optionsobject Optional Parameters (optional, default{})
Examples
setDefaultLimit() //=> 25Returns number Default Limit value
addBlockFiltersToPipeline
Add Block Filters to Pipeline
Parameters
pipelineArray<object> MongoDB Pipelineoptionsobject Optional Parameters (optional, default{})options.irreversibleboolean? Irreversible transaction (eg: true/false)options.block_numnumber? Filter by exact Reference Block Numberoptions.block_idstring? Filter by exact Reference Block IDoptions.lte_block_numnumber? Filter by Less-than or equal (<=) the Reference Block Numberoptions.gte_block_numnumber? Filter by Greater-than or equal (>=) the Reference Block Number
Returns void Appends results to pipeline
getAccount
Get Account Details
Parameters
clientMongoClient MongoDB Clientnamestring Account NameoptionsObject Optional Parameters (optional, default{})options.lte_block_numnumber? Filter by Less-than or equal (<=) the Reference Block Number
Examples
const name = "eosnationftw";
const options = {
block_num: 6000000,
};
const result = await getAccount(client, name, options);
// {
// name: 'eosnationftw',
// block_num: 2092984,
// stake_quantity: 1.8,
// stake_net_quantity: 0.9,
// stake_cpu_quantity: 0.9,
// actions: [...Actions]
// }Returns Object Account Details
getAccounts
EOSIO MongoDB Accounts
Parameters
clientMongoClient MongoDB ClientoptionsObject Optional Parameters (optional, default{})options.abiboolean? Does abi exist (eg: true/false)options.limitnumber Limit the maximum amount of of actions returned (optional, default25)options.sortobject? Sort by ascending order (1) or descending order (-1) (eg: {controlled_account: -1})options.skipnumber? Skips number of documentsoptions.matchobject? Match by entries (eg: {controlled_account: "eosio.saving"})
Examples
const options = {
match: {controlled_account: "eosio.saving"},
};
const results = await getAccounControls(client, options);
console.log(await results.toArray());Returns AggregationCursor<AccountControls> MongoDB Aggregation Cursor