Data disappear after 3 transactions

for the following code, what I do was in each transaction , get a document from db, add a key to it, and save it back, then print the num of keys in this doc.
Obviously, it should print 1 2 3. However, in the last transaction, it prints 0, which means all the data in the doc are lost.

#include
#include “include/cbl/CouchbaseLite.h”
#include “include/cbl++/CouchbaseLite.hh”
int main() {
cbl::Database db(“bucket”, {"/tmp", kCBLDatabase_Create});
db.beginBatch();
cbl::MutableDocument doc2 = db.getMutableDocument(“foo”);
if (!doc2.valid()){
doc2 = cbl::MutableDocument(“foo”);
}
doc2[“var1”]= 1;
cbl::Document saved = db.saveDocument(doc2);
std::cout<<saved.properties().count()<<std::endl;
db.endBatch();
db.beginBatch();
doc2 = db.getMutableDocument(“foo”);
doc2[“var2”]= 2;
saved = db.saveDocument(doc2);
std::cout<<saved.properties().count()<<std::endl;
db.endBatch();
db.beginBatch();
doc2 = db.getMutableDocument(“foo”);
doc2[“var3”]= 3;
saved = db.saveDocument(doc2);
std::cout<<saved.properties().count()<<std::endl;
db.endBatch();
db.deleteDatabase();
return 0;
}

I think this is a bug.
p.s The method db.beginBatch() and db.endBatch() is manually added to Database.hh by me. Their implementation is :
void beginBatch(){
CBLError error;
check(CBLDatabase_BeginBatch(ref(), &error), error);
}
void endBatch(){
CBLError error;
check(CBLDatabase_EndBatch(ref(), &error), error);
}

I see you’ve filed this as an issue on Github … that’s the appropriate place for bug reports.