<>fabric Is the state database (couchdb) Add index

fabric State database leveldb and couchdb, among couchdb Support rich query ,leveldb I won't support it .
Because the efficiency of the blockchain itself is very low , In the case of rich queries , It is easy to cause the connection timeout problem because the query time is too long , To improve couchdb Query speed of , General meeting couchdb Add index .

by couchdb Adding indexes can be created in the couchdb The container is then created manually using the command , This creation method is limited and prone to errors , Therefore, it is generally recommended that the chaincode( Smart contract ) And automatically add indexes when upgrading smart contracts .

<> Create smart contract

stay chaincode Create in project directory META-INF\statedb\couchdb\indexes catalog , stay indexes
Create a json file , The file name can be customized .

Sample file content :
{ "index": { "fields": [ // The columns of the index "bizUUID", "bizType", "blockTimeTamp" ] },
"ddoc": "indexBizUBizTBTTDoc", // Index document name , Customizable "name": "indexTest", // Index name , Customizable
"type": "json" }
<> Use index

After instantiation of smart contract ,couchdb A channel name is automatically created _ Database of smart contract names , When you enter the database, you can see the currently used index .

The presence of this document in the database indicates that the index was created successfully .

If you encounter problems during operation , Welcome to comment , Let's communicate and grow together .

©2019-2020 Toolsou All rights reserved,
Send love - A little romance for programmers VHDL—— Design of frequency divider Python Implementation of Hanoi Tower code It's over , Starting salary 30khtml+css+js Make a simple website home page QQ Login interface implementation Hill sorting of sorting algorithm ——c++ realization 【 Wechat applet learning 】 Netease music cloud code page implementation details Resume the 13th session python Blue Bridge Cup 2022 Solution to the 13th Blue Bridge Cup ( whole )