Hi, does Couchbase Lite 2.0.2 for Android have support for deleting documents directly through query?
For example, with SQLite, I can call something like this to delete all users:
SQLiteDatabase database = getWritableDatabase();
database.execSQL("DELETE FROM user");
If I understand the QueryBuilder correctly, the way to achieve this same behavior with Couchbase Lite is to do the following:
database.inBatch(new Runnable()
{
@Override public void run()
{
try
{
Query query = QueryBuilder.select(SelectResult.expression(Meta.id)).from(DataSource.database(database)).where(Expression.property("type").equalTo(Expression.string("user")));
ResultSet resultSet = query.execute();
for(Result result : resultSet)
{
String id = result.getString(0);
Document document = database.getDocument(id);
if(document != null)
{
database.delete(document);
}
}
}
catch(Exception exception)
{
Log.e(exception);
}
}
});
Can you confirm if this is the case?
Thanks in advance!