Regarding the query listeners(Couchbase-lite-C, C++ API, See the signature below - Sample 1): The callback is called with a parameter of type cbl::Query::Change, which does not contain the id or any identification of the document that the change refers to.
Is this a limitation of the API or is there a way to use the cbl::Query::Change parameter to find the document it refers to? Sample 2 contains the actual code where the problem can be observed.
Sample 1:
/** Registers a change listener callback to the query, turning it into a "live query" until
the listener is removed (via \ref ListenerToken::remove() ).
When the first change listener is added, the query will run (in the background) and notify
the listener(s) of the results when ready. After that, it will run in the background after
the database changes, and only notify the listeners when the result set changes.
@param callback The callback to be invoked.
@return A Change Listener Token. Call \ref ListenerToken::remove() method to remove the listener. */
[[nodiscard]] inline ChangeListener addChangeListener(ListenerToken<Change>::Callback callback);
Sample 2:
query.addChangeListener([](cbl::Query::Change change) {
cbl::ResultSet rs = change.results();
if (!rs.valid())
{
return;
}
cbl::ResultSetIterator it = rs.begin();
std::vector<fleece::MutableDict> results;
while (it != rs.end())
{
cbl::Result ri = *it;
results.push_back(ri[0].asDict().mutableCopy());
++it;
}
// Here results contains the changes, but the documents to whom they belong is unknown.
}