I am using couchbase-sync-gateway-enterprise_1.5.0-377 with couchbase-server-enterprise_5.0.0-beta for testing write data by N1QL and Sync Gateway in the same bucket.
my sync gateway looks like as following:
can I filter the invalid documents by N1QL via some META() info, such as xattr?
when I update some document by UPDATE statement via Query Workbench,I found that UPDATE will trigger SG Creation Processing (oldDoc == null && !doc._deleted ). can any update cause SG update Processing (oldDoc != null && !doc._deleted )?
when I delete document by DELETE statement via Query Workbench,I found DELETE will not trigger SG delete Processing (doc._deleted) can any delete cause SG delete Processing (doc._deleted )?
As you’ve seen, any writes through Couchbase Server need to get run through the Sync Function to apply security before they can be accessed by Sync Gateway. Your N1QL updates can’t be imported for use by Sync Gateway because they are being rejected by your Sync Function.
In the upcoming Beta 2 of Sync Gateway 1.5 we’ll be adding some additional functionality to the Sync Function to give you more granular control over how imports are handled. We’re adding an ‘isImport’ built-in function that will let you identify whether the document being processed is SG attempting to import a document that was not written through Sync Gateway, and modify security rules as needed.
For your specific questions:
Question 1: can I filter the invalid documents by N1QL via some META() info, such as xattr?
N1QL doesn’t have the ability to query extended attributes in 5.0. It’s on the roadmap for a future release, but until then you’ll have to craft a N1QL query based on your sync function (e.g. based on the name property in this case).
Question 2: can any update cause SG update Processing (oldDoc != null && !doc._deleted )?
When a document is updated via N1QL (or the SDK) is imported by Sync Gateway, oldDoc will be empty (as the previous body no longer exists). Currently we don’t provide a way to identify in the Sync Function whether a document being imported is an insert or an update, but we could consider an enhancement to add that. If you have a use case for this functionality that’s not covered by the upcoming isImport function, please file a github issue in the Sync Gateway repo with some details and we can review for 1.5 GA.
Question 3: can any delete cause SG delete Processing (doc._deleted )?
_rev is stored with the rest of Sync Gateway’s metadata (in a system extended attribute). As mentioned above, N1QL doesn’t yet support accessing this data.
I’d be interested in your use case for retrieving _rev - it may help get this work prioritized. Is it primarily for development time visibility into the doc properties, or do you also have a production use case for N1QL retrieval of _rev?
I want to use Couchbase Mobile (may be future for the couchbase lite or pouchdb) and Sync Gateway _changes API for documents update notification. and I also want to use N1QL to get flexibly query.so I need write document by SG and query document by N1QL.