-
Notifications
You must be signed in to change notification settings - Fork 12
Purge doc with more revisions
Chang Hua Guo edited this page Jan 3, 2017
·
1 revision
#Purge doc with more revisions
##create a document with more revisions
a. create a db with doc apple
macgch:couchdb chguo$ curl -X PUT foo:[email protected]:15984/testdb
{"ok":true}
macgch:couchdb chguo$ curl -X POST foo:[email protected]:15984/testdb -H "Content-Type: application/json" -d @apple.json
{"ok":true,"id":"apple","rev":"1-db30a6971ffbf55b1a009c79d1643e06"}
macgch:couchdb chguo$ curl -X POST foo:[email protected]:15984/testdb -H "Content-Type: application/json" -d @search.json
{"ok":true,"id":"_design/search","rev":"1-8a4ac7cb2445eb8c75271fd7bb84441c"}
b. update doc
macgch:couchdb chguo$ curl -X PUT foo:[email protected]:15984/testdb/apple -H "Content-Type: application/json" -d "{\"_rev\":\"1-db30a6971ffbf55b1a009c79d1643e06\", \"size\":2}"
{"ok":true,"id":"apple","rev":"2-778944397d87c99a0c20f28253ad1a66"}
macgch:couchdb chguo$ curl -X PUT foo:[email protected]:15984/testdb/apple -H "Content-Type: application/json" -d "{\"_rev\":\"2-778944397d87c99a0c20f28253ad1a66\", \"size\":3}"
{"ok":true,"id":"apple","rev":"3-588cfe44a9ad1f6594abaa089a1d17c5"}
##Search it
macgch:couchdb chguo$ curl -X GET foo:[email protected]:15984/testdb/_design/search/_search/index?q="apple"
{"total_rows":1,"bookmark":"g2wAAAABaANkAA9ub2RlMUAxMjcuMC4wLjFsAAAAAmEAbgQA_____2poAkY_8AAAAAAAAGEBag","rows":[{"id":"apple","order":[1.0,1],"fields":{}}]}
##Purge doc
([email protected])1> DBFullName = <<"shards/00000000-ffffffff/testdb.1483436988">>.
<<"shards/00000000-ffffffff/testdb.1483436988">>
([email protected])2> {ok, Db} = couch_db:open_int(DBFullName, []).
{ok,{db,<<"shards/00000000-ffffffff/testdb.1483436988">>,
"/Users/chguo/Documents/git/couchdb/dev/lib/node1/data/shards/00000000-ffffffff/testdb.1483436988.couch",
{couch_bt_engine,{st,"/Users/chguo/Documents/git/couchdb/dev/lib/node1/data/shards/00000000-ffffffff/testdb.1483436988.couch",
<0.9082.3>,#Ref<0.0.1.135721>,
[before_header,after_header,on_file_open],
{db_header,6,4,0,
{16634,{2,0,{size_info,457,385}},245},
{16879,2,248},
nil,0,nil,163,1000,<<"aaedf021dff3"...>>,
[{'[email protected]',...}],
0,1000,...},
false,
{btree,<0.9082.3>,
{16634,{2,0,{size_info,457,385}},245},
#Fun<couch_bt_engine.id_tree_split.1>,
#Fun<couch_bt_engine.id_tree_join.2>,undefined,
#Fun<couch_bt_engine.id_tree_reduce.2>,snappy},
{btree,<0.9082.3>,
{16879,2,248},
#Fun<couch_bt_engine.seq_tree_split.1>,
#Fun<couch_bt_engine.seq_tree_join.2>,undefined,
#Fun<couch_bt_engine.seq_tree_reduce.2>,snappy},
{btree,<0.9082.3>,nil,
#Fun<couch_bt_engine.local_tree_split.1>,
#Fun<couch_bt_engine.local_tree_join.2>,undefined,nil,
snappy},
snappy,
{btree,<0.9082.3>,nil,undefined,undefined,undefined,
#Fun<couch_bt_engine.purge_tree_reduce.2>,snappy}}},
<0.9081.3>,nil,4,<<"1483436988125126">>,
{user_ctx,null,[],undefined},
[],[],nil,nil,nil,
[{engine,<<"couch">>},
{placement,undefined},
{q,"1"},
{n,"1"},
{default_security_object,[]}],
undefined}}
([email protected])3> FDI = couch_db:get_full_doc_info(Db, <<"apple">>).
{full_doc_info,<<"apple">>,4,false,
[{1,
{<<219,48,166,151,31,251,245,91,26,0,156,121,209,100,62,6>>,
{leaf,false,172,1,{size_info,83,120},[]},
[{<<119,137,68,57,125,135,201,154,12,32,242,130,83,173,26,
102>>,
{leaf,false,8379,3,{size_info,63,100},[]},
[{<<88,140,254,68,169,173,31,101,148,171,170,8,...>>,
{leaf,false,16571,4,{size_info,63,100},[]},
[]}]}]}}],
{size_info,209,100},
[]}
([email protected])4> rd(doc_info, {id = <<"">>, high_seq = 0, revs = []}).
doc_info
([email protected])5> rd(rev_info, {rev, seq =0, deleted = false, body_sp = nil}).
rev_info
([email protected])6> #doc_info{ revs = [#rev_info{rev = Rev1} | _] } = couch_doc:to_doc_info(FDI).
#doc_info{id = <<"apple">>,high_seq = 4,
revs = [#rev_info{rev = {3,
<<88,140,254,68,169,173,31,101,148,171,170,8,154,29,23,
197>>},
seq = 4,deleted = false,body_sp = 16571}]}
([email protected])7> {ok, {_, [{ok, _}]}} = couch_db:purge_docs(Db, [{<<"apple">>, [Rev1]}]).
{ok,{1,
[{ok,[{3,
<<88,140,254,68,169,173,31,101,148,171,170,8,154,29,
23,197>>}]}]}}
##Search it again
macgch:couchdb chguo$ curl -X GET foo:[email protected]:15984/testdb/_design/search/_search/index?q="apple"
{"total_rows":0,"bookmark":"g2o","rows":[]}