How to use query

I posted my question to stackoverflow, But I’m going to post it to here. Please check my question and help me. I’m very confused about the query.

Answered here on StackOverflow. Copied here.

Views build a static index that is persistent. The map function for a View must be a pure function, meaning it can’t depend on anything but the document passed in. If your map function relies on anything (like the current date), you’ll get inconsistent results. It looks like this may be what’s happening in your case.

Rules for Couchbase Lite View map functions:

  • It must be a “pure” function: That means any time it’s called with the same input, it must produce exactly the same output. In other words, it can’t use any external state, just its input JSON.
  • It can’t have side effects: It shouldn’t change any external state, because it’s unpredictable when it’s called or how often it’s called or in what order documents are passed to it.
  • It must be thread-safe: It may be called on a background thread belonging to the indexer, or even in parallel on several threads at once.

See the documentation on Couchbase Lite Views.

The original question asked how to get an appointment by date.

The answer depends on how you’re structured your documents. Here’s an outline of a possible solution (simple):

  1. Create a View that emits the appointment date. (Note you don’t normally need to emit the entire document, like in your original code. The query automatically has access to the document ID. You can use that to retrieve the full document if you need it.)
  2. Create a query
  3. Configure keys or startKey and endKey on the query to restrict it to the results you want.

See the Query documentation for more information.

Thank so much.
please check my document structure of couchbase.
And please check this respository on git.(
I have 198457 documents in a bucket and the data transfered from mssql database.
I need to transfer the data from couchbase to mssql and from mssql to couchbase with above java project.
So I can’t change the json structure. Please check my json structure and help me.
In the document, docID has table name of MSSQL database (appointments_appointment:1).

We don’t have the resources to do that amount of support on a volunteer basis. Couchbase offers commercial support contracts that can involve reviewing code / document design and suggesting improvements.