Can we use n1ql query in Couchbase-Lite-PhoneGap-Plugin

Can we use n1ql query in Couchbase-Lite-PhoneGap-Plugin… As it is hybrid needs to do using rest api.

I don’t think that from a security perspective you would want your mobile clients in the Internet have direct access to the couchbase server bucket. The typical pattern is to have a simple web service (Python, node, java, c, go , .net …) that interfaces with Couchbase service using one of our many SDKs. This web service would then support a simple REST APIs that your mobile app can query into .

On a related note, In 2.0 version of Couchbase Lite (now in Developer Build), we do have support for N1QL like queries that can be made directly against the CB lite data store. We don’t have a phone gap plugin for it as yet (CC @jens)

It’s not likely that 2.0 will support PhoneGap … the REST API is another entire API to implement, on top of all the different languages. Probably this will come in 2.1.

@jens
Can you suggest how can and filter data based on single key from composite key…

My View:
function(doc, meta) {
if (doc.type && doc.updatedOn && doc.title) {
var value = {
id: doc._id,
type: doc.type,
title: doc.title,
description: doc.description,
updatedOn: doc.updatedOn
};
emit([doc.updatedOn, doc.type], value);
}
}

So am trying filter data using “type”

If you want type to be the primary criterion you search on, it has to be the first item in the key.

@jens Yes but my situation is sort should be based on updatedOn and criterion should be based on type… will it works.

A query can’t sort on a different criterion than you’re searching for. If you need to do that, you’ll have to sort the rows yourself afterwards.

@jens how it will work in real time… I may have 1000 records where I will pull only first 10 records which should be latest.

I misspoke above. You can search for equality of property A, and for a range of values of property B, and sort by property B. You do this by emitting keys like [A, B], and then querying with a key range like [A, b0] to [A, b1].

In your case you’d want to emit [type, updatedOn] in the map function. Then in the query the startKey is [desiredType, {}], descending is true, and limit is 10.

1 Like

@jens thank you. Some what concepts for different…

@jens So I need to create query views for each attribute which ever want to use for sort or search… Am I right? Please update

we wanted to start upgrading to 2.0 but we do use Cordova. When will 2.0 be available with Cordova support?

We don’t have a schedule for that. We realize a number of people use PhoneGap/Cordova, but it requires implementing another API (REST) and we’re focusing on the platform-native APIs first.