I have a document of type 'object' which may be owned by a 'user' document via an 'owned_by' property on the 'object' document. All 'object' documents also have a 'latitude' and 'longitude' property and a 'source_ref' property that references another document of type 'source'.
In iOS I am querying 'object' documents using 2 different views and then setting them up as live queries that run in the background. The first view map function queries all documents where the 'owned_by' property contains the current users email and the second uses the boundingbox function to get all documents within close proximity to the user via their 'latitude' and 'longitude' properties. The properties are constantly changing and thus the live query will potentially be returning new 'object' documents several times a minute.
This all works fine but the issue I am having is that every time the app pulls all the document of type 'object' using these live query views, I need to then use their 'source_ref' property to go and pull a very small subset of 'source' documents specifically by their IDs from the server. Up to now I have just been pulling all the 'source' documents so I have them to hand when I need them but there could over time potentially be tens of thousands of documents of type 'source' and I am only interested in pulling a very small subset by their ID every time the live queries return results.
It is my understanding that I can't create a dynamic condition for a view (i.e. the 'source_ref' properties of the 'object' documents as they are returned by a live query) so is there a simple way I am missing that this can be achieved using views map reduce function or can I simply create an array of the document ID's I want to pull from the server to my local db and query them one by one in the background? I've looked at the documentation on simulating relationships but this seems a very SQL approach and maybe not the best way to achieve want I want to do.
Any advice on how you would approach this would be much appreciated.
Toby
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/56909e25-2235-4e1c-8db5-8a83b8163374%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Aug 27, 2014, at 9:13 AM, Toby UP <tob...@gmail.com> wrote:
In iOS I am querying 'object' documents using 2 different views and then setting them up as live queries that run in the background. The first view map function queries all documents where the 'owned_by' property contains the current users email and the second uses the boundingbox function to get all documents within close proximity to the user via their 'latitude' and 'longitude' properties. The properties are constantly changing and thus the live query will potentially be returning new 'object' documents several times a minute.
It is my understanding that I can't create a dynamic condition for a view (i.e. the 'source_ref' properties of the 'object' documents as they are returned by a live query) so is there a simple way I am missing that this can be achieved using views map reduce function or can I simply create an array of the document ID's I want to pull from the server to my local db and query them one by one in the background?
On Aug 27, 2014, at 9:13 AM, Toby UP <tob...@gmail.com> wrote:
In iOS I am querying 'object' documents using 2 different views and then setting them up as live queries that run in the background. The first view map function queries all documents where the 'owned_by' property contains the current users email and the second uses the boundingbox function to get all documents within close proximity to the user via their 'latitude' and 'longitude' properties. The properties are constantly changing and thus the live query will potentially be returning new 'object' documents several times a minute.I'm sort of confused by that last statement. If the live query is returning new results, that implies the database changed. But from your use case it sounds like it's the user's location that changes. That wouldn't cause the live query to update; instead you'd presumably be running a new query with different lat/lon coords.
It is my understanding that I can't create a dynamic condition for a view (i.e. the 'source_ref' properties of the 'object' documents as they are returned by a live query) so is there a simple way I am missing that this can be achieved using views map reduce function or can I simply create an array of the document ID's I want to pull from the server to my local db and query them one by one in the background?I think there are two different issues here (or maybe I'm just confused.)First there's the issue of joins. You can't directly join from the object docs to the source docs. You'll need to collect the set of source_ref values and then get those documents. If they're local, just call [database documentWithID:] for each one. (CBLDatabase has a document cache and will never instantiate multiple CBLDocument objects for the same ID.)
Second, it sounds like you want to pull the source documents lazily from the server instead of replicating the entire data set to the device. You'll need to do that by setting the documentIDs property of the replication. Two things to keep in mind:
- The replicator only checks this property when the replication starts. That means that, if you change the property on a running CBLReplication, you'll need to stop and re-start it.
- If you want to keep getting updates of all the source documents you've downloaded, you'll need to persistently store the entire set of source document IDs somewhere so you can set the replication's documentIDs on re-launch of the app.
(I know this isn't ideal, especially condition 2. Our architecture isn't yet optimized for keeping a subset of the server database; that's a high priority feature for version 2.0.)
On Sep 1, 2014, at 6:47 AM, Toby UP <tob...@gmail.com> wrote:The majority of the 'source' documents won't exist locally. However if they don't and I make a call to the local database via [database documentWithID:] will it create a blank document and then subsequently pull an existing document with that ID from the server seeing as it is now created locally.
On Sep 1, 2014, at 6:47 AM, Toby UP <tob...@gmail.com> wrote:Also just to clarify there is no way to do what Alexander suggested in the reply above (have you tried joining with views? http://docs.couchdb.org/en/latest/couchapp/views/joins.html) and create a view that includes the 'source' document (in full) as an adjacent row for each 'object' document row using it's 'source_ref' property every time the live query returns results?
emit(@[doc[@"_id"], @"1"], @{@"_id": doc[@"source_ref"]});
And this is what I'm getting when iterating through my rows:
CBLQueryRow[key=["321D285B-E684-43FF-AA84-B3661732A654","1"]; value={"_id":"68B3E7A6-5391-449B-8D83-17C83EA7BBDC"}; id=321D285B-E684-43FF-AA84-B3661732A654]
There is obviously a lot more data in the 'source' document than just the _id so it doesn't seem to be getting the full document. Am I missing something? Do I have to set the equivalent of include_docs=true on the CBLQuery in iOS or should it be picking up that it's a linked document automatically by the fact I am using '_id'. This is using a liveQuery incase that makes any difference.
On Sep 1, 2014, at 2:56 PM, Toby UP <tob...@gmail.com> wrote:Do I have to set the equivalent of include_docs=true on the CBLQuery in iOS
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/9ef08e16-fe4c-4081-86fd-b9cb5f7d8e12%40googlegroups.com.
in vanilla couchdb I have to add include_docs=truedon't know for sure about couchbase lite but I bet it's the same
2014-09-01 23:56 GMT+02:00 Toby UP <tob...@gmail.com>:
On Monday, 1 September 2014 18:56:24 UTC+1, Jens Alfke wrote:On Sep 1, 2014, at 6:47 AM, Toby UP <tob...@gmail.com> wrote:Also just to clarify there is no way to do what Alexander suggested in the reply above (have you tried joining with views? http://docs.couchdb.org/en/latest/couchapp/views/joins.html) and create a view that includes the 'source' document (in full) as an adjacent row for each 'object' document row using it's 'source_ref' property every time the live query returns results?That feature is supported.—JensI have just been trying this and am not getting the full document dictionary.My view emit looks like this:emit(@[doc[@"_id"], @"1"], @{@"_id": doc[@"source_ref"]});
And this is what I'm getting when iterating through my rows:
CBLQueryRow[key=["321D285B-E684-43FF-AA84-B3661732A654","1"]; value={"_id":"68B3E7A6-5391-449B-8D83-17C83EA7BBDC"}; id=321D285B-E684-43FF-AA84-B3661732A654]
There is obviously a lot more data in the 'source' document than just the _id so it doesn't seem to be getting the full document. Am I missing something? Do I have to set the equivalent of include_docs=true on the CBLQuery in iOS or should it be picking up that it's a linked document automatically by the fact I am using '_id'. This is using a liveQuery incase that makes any difference.
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchbase+unsubscribe@googlegroups.com.
If you have a set of doc IDs that you want to pull immediately, you should create a new one-shot pull replication and set its documentIDs property. Thereafter, to keep the docs up to date, you should run a continuous replication whose documentIDs is set to all the documents that you've ever brought in this way. (This is awkward but as I said, there isn't a clean way to do it yet.)
On Sep 13, 2014, at 1:52 AM, Rajagopal V <raja...@gmail.com> wrote:I have a continuous replication that brings some specified "types" of documents. Now when the user does a Search on his mobile for other "types", there is a REST call that goes to my PHP server that returns document ids back to the mobile(these are not yet available in the mobile). If I were to do a one-shot pull replication using the returned ids, I assume that those will be available in the mobile and subsequently be replicated continuously when I update them through the mobile.
On Sep 13, 2014, at 1:52 AM, Rajagopal V <raja...@gmail.com> wrote:I have a continuous replication that brings some specified "types" of documents. Now when the user does a Search on his mobile for other "types", there is a REST call that goes to my PHP server that returns document ids back to the mobile(these are not yet available in the mobile). If I were to do a one-shot pull replication using the returned ids, I assume that those will be available in the mobile and subsequently be replicated continuously when I update them through the mobile.In 1.0.2 the answer is no; a one-shot replication will only update the documents once. To keep all the docs you've pulled fresh, you'll have to keep track of all of their IDs (persistently) and run a continuous pull replication with those doc IDs.
In 1.0.2 the answer is no; a one-shot replication will only update the documents once. To keep all the docs you've pulled fresh, you'll have to keep track of all of their IDs (persistently) and run a continuous pull replication with those doc IDs.Now, on the iOS branch feature/subset I've added a couple of new methods on CBLReplication to make what you're doing easier:
On Sep 18, 2014, at 10:36 AM, Rajagopal V <raja...@gmail.com> wrote:In CBLRemoteQuery, the live query mechanism is not yet implemented.