Hello,
Just starting with Couchbase and stuck with very simple N1QL command:
CBLError err;
int errorPos;
CBLQuery* query = CBLDatabase_CreateQuery(db, kCBLN1QLLanguage, FLSTR(“DELETE FROM _ WHERE type = ‘myobject’”), &errorPos, &err);
Return error and position is 11.
During 2 hours I can’t figure out what’s wrong with this command.
Could someone help me ?
yes, that’s the way. For example, something like,
let q = try db.createQuery(“SELECT META().id FROM coll WHERE …”)
let resultSet = try q.execute()
try db.inBatch {
for r in resultSet {
if let doc = collection.document(id: r.string(at: 0)) {
try collection.deleteDocument(doc);
}
}
}
Thank you,
Finally I get sources from git, build and use this code:
cbl::Transaction tr(db);
auto query = db.createQuery(kCBLN1QLLanguage, "SELECT meta().id FROM _ WHERE type = 'type'");
if (!query) {
cout << "fillDb: Can't create query" << endl;
return -1;
}
auto rs = query.execute();
for (auto it = rs.begin(); it != rs.end(); ++it) {
auto doc = db.getDocument((*it)[0].asString());
if (doc)
db.deleteDocument(doc);
}
tr.commit();
Works well, but if it needs to load all records in rowset, so if I have many rows - it eats a lot of memory. Of course it’s possible to make several queries with limit.
Anyway it works.