I am making a process that retrieves a list of documents and must make updates to them and send them through Sync Gateway so those updates are pushed to a mobile user. I see that I can do a bulk_get through sync gateway provided I know the document Ids ahead of time, but is it possible to send a n1ql query through sync gateway to retrieve the documents? Alternately, I would have to query using 8091 port to get the document Ids, then do a bulk get for those documents. Is that how I will have to do it?
Currently there isn’t any pass-through N1QL support in Sync Gateway. Some early investigation has been done (the PR linked by atom_yang above), but it hasn’t been made production-ready yet.
The usual way for dealing with subsets of documents through Sync Gateway would be to use channels. If you’ve already reviewed channels and found that they don’t work for you, I’d be interested to hear the specifics on why not.
Essentially, what I’m trying to do is get data out of a SQL db to add to existing documents. The documents I’ll be updating can easily be gotten through a simple n1ql query due to our key naming convention, so I will get that list of documents, get the data that needs to go into them, update the docs with the new data, send them back through SG so the new data gets synced to the mobile users. This would be a scheduled job and the list of documents that need to be updated will be different with each run, and that is what makes using channels problematic.
If the easiest way to get your list of document IDs is via N1QL, and it’s a server-side update process (i.e. it’s not clients doing the update), then I think your original suggestion is best. Use N1QL to query Couchbase Server directly to get your list of document IDs, and then use that as input for the subsequent SG requests.
The main benefit that you’d get from a future enhancement to support pass-through N1QL queries through Sync Gateway would be security for N1QL requests made through the SG public API. In this scenario, that doesn’t sound like a concern?
That would not be a concern in this case and it is an internal process sending the N1QL query. The pass-through would just remove the step of getting the Ids directly from cb initially to then pass to SG
Alternately, is it possible to get the documents from couchbase directly and then cast them to the format sync gateway is expecting to perform the updates? Or will that cause issues? It seems like that should work.