Empty result from view

51 views
Skip to first unread message

dyowee

unread,
Jul 25, 2012, 10:04:11 PM7/25/12
to mobile-c...@googlegroups.com
Good day,
 
I was able to create a MAPBLOCK for my view, and enabled logging in TouchDB, but I'm getting no results from the query. I tried the same query in futon, and it is working ok. I also checked the TouchDB with SQLite Viewer in FireFox, and it contains data. Here is from the log:
 
touchdb:///config/_design/appuser/_view/by-username-password?include_docs=true&startkey=%5b%22guest%22%2c%22password%22%5d&endkey=%5b%22guest%22%2c%22password%22%5d

Jens Alfke

unread,
Jul 25, 2012, 10:45:15 PM7/25/12
to mobile-c...@googlegroups.com

On Jul 25, 2012, at 7:04 PM, dyowee <csharpen...@gmail.com> wrote:

I was able to create a MAPBLOCK for my view, and enabled logging in TouchDB, but I'm getting no results from the query. I tried the same query in futon, and it is working ok. I also checked the TouchDB with SQLite Viewer in FireFox, and it contains data. Here is from the log:

I have no idea, unless you actually show us the code that registers the map function.

—Jens

dyowee

unread,
Jul 25, 2012, 10:57:53 PM7/25/12
to mobile-c...@googlegroups.com
I'm doing this in MonoTouch:
 
CouchDesignDocument designDoc = server.DatabaseNamed("config").DesignDocumentWithName("appuser");
designDoc.DefineViewNamedMap("by-username-password", (NSDictionary doc, CouchEmit emit) =>
 {
   NSString username = (NSString)doc.ObjectForKey(new NSString("UserName"));
   NSString password = (NSString)doc.ObjectForKey(new NSString("Password"));
   if (username != null && password != null)
       emit(NSArray.FromNSObjects(username, password), doc);
  } , "1.0");
designDoc.SaveChanges();
 

Noong Huwebes, Hulyo 26 2012 10:45:15 UTC+8, si Jens Alfke ay sumulat:

Jens Alfke

unread,
Jul 26, 2012, 1:33:24 AM7/26/12
to mobile-c...@googlegroups.com
I don't know anything about MonoTouch, but I don't see anything obviously wrong in that code. You may need to ask whoever wrote the binding of TouchDB to MonoTouch.

In the URL query you gave, both the startkey and endkey are equal to ["guest","password"]. So unless you have exactly such a key in the view index, you won't get any results. Are you sure you do?

—Jens

dyowee

unread,
Jul 26, 2012, 5:31:12 AM7/26/12
to mobile-c...@googlegroups.com
Yes sir, I tried the same query on a server to which I replicated to. Thank you.

Noong Huwebes, Hulyo 26 2012 13:33:24 UTC+8, si Jens Alfke ay sumulat:

dyowee

unread,
Aug 1, 2012, 6:42:22 PM8/1/12
to mobile-c...@googlegroups.com
Good day sir,
 
I'm moving my code to Objective-C instead of MonoTouch, but I'm getting some issues where for some queries, I don't get any results.
touchbd://datastore/_design/photo/_view/by-guestid?startkey=%5b%22guest-b31a48fe-6d56-41d9-b63e-8351e376f463%22%5d&endkey=%5b%22guest-b31a48fe-6d56-41d9-b63e-8351e376f463%22%5d
 
design = [db designDocumentWithName: @"photo"];
[design defineViewNamed:@"by-guestid" mapBlock: MAPBLOCK({
NSString* clientId = [doc objectForKey: @"ClientId"];
if (clientId)
emit(clientId, doc);
}) version: @"1.0"];

Noong Huwebes, Hulyo 26 2012 13:33:24 UTC+8, si Jens Alfke ay sumulat:

Jens Alfke

unread,
Aug 1, 2012, 6:52:14 PM8/1/12
to mobile-c...@googlegroups.com

On Aug 1, 2012, at 3:42 PM, dyowee <csharpen...@gmail.com> wrote:

I'm moving my code to Objective-C instead of MonoTouch, but I'm getting some issues where for some queries, I don't get any results.

This is going to return only the item with key "guest-b31a48fe-6d56-41d9-b63e-8351e376f463". You're sure you have a document with that value for a ClientId?

What rows do you get if you remove the startkey and endkey parameters? Do they include the one you wanted?

—Jens

dyowee

unread,
Aug 1, 2012, 7:12:39 PM8/1/12
to mobile-c...@googlegroups.com
Yes sir, I tried then to retrieve all rows, the document is in there with the GuestId(not ClientId, sorry).

Noong Huwebes, Agosto 02 2012 06:52:14 UTC+8, si Jens Alfke ay sumulat:

dyowee

unread,
Aug 1, 2012, 11:13:27 PM8/1/12
to mobile-c...@googlegroups.com
My other queries/views seems to work ok, but some similar to this I always get zero results. It is because of the id format?
 
Thanks,
Joey
Noong Huwebes, Agosto 02 2012 06:52:14 UTC+8, si Jens Alfke ay sumulat:

Jens Alfke

unread,
Aug 1, 2012, 11:32:00 PM8/1/12
to mobile-c...@googlegroups.com

On Aug 1, 2012, at 8:13 PM, dyowee <csharpen...@gmail.com> wrote:

My other queries/views seems to work ok, but some similar to this I always get zero results. It is because of the id format?

I don't know. What do all the query rows look like? Can you add some code that will dump the entire output from querying the view with no startkey/endkey parameters, and post that?

—Jens

dyowee

unread,
Aug 1, 2012, 11:48:44 PM8/1/12
to mobile-c...@googlegroups.com

All:


design = [db designDocumentWithName: @"photo"];
 

        [design defineViewNamed:@"_all" mapBlock: MAPBLOCK({
 
            NSString* docId = [doc objectForKey: @"_id"];
 
            if ([docId rangeOfString:@"photo-"].location == 0)
 
                emit(nil, nill);
 
        }) version: @"1.0"];

Filtered:


design = [db designDocumentWithName: @"photo"];
 
        [design defineViewNamed:@"by-guestid" mapBlock: MAPBLOCK({
 

            NSString* guestId= [doc objectForKey: @"GuestId"];
 
            if (guestId)
 
                emit(guestId, doc);
 
        }) version: @"1.0"];
Noong Huwebes, Agosto 02 2012 11:32:00 UTC+8, si Jens Alfke ay sumulat:

dyowee

unread,
Aug 2, 2012, 12:32:26 AM8/2/12
to mobile-c...@googlegroups.com
Hmm, is it a problem if I have only one key in a startkey/endkey but it has square brackets?

Noong Huwebes, Agosto 02 2012 11:32:00 UTC+8, si Jens Alfke ay sumulat:

dyowee

unread,
Aug 2, 2012, 1:17:04 AM8/2/12
to mobile-c...@googlegroups.com
It seems that was the issue sir. It was working with Couchbase mobile, though...

Noong Huwebes, Agosto 02 2012 11:32:00 UTC+8, si Jens Alfke ay sumulat:

Jens Alfke

unread,
Aug 2, 2012, 1:28:19 AM8/2/12
to mobile-c...@googlegroups.com

On Aug 1, 2012, at 9:32 PM, dyowee <csharpen...@gmail.com> wrote:

Hmm, is it a problem if I have only one key in a startkey/endkey but it has square brackets?

Oh! Yes, your map function emits the keys as strings, but your query is giving the startkey and endkey as arrays. Arrays are not the same as strings, so this isn't going to find anything. (Look at the CouchDB collation spec: all strings sort before all arrays.)

Take the (quoted) square brackets out of your query URL and it should work.

It seems that was the issue sir. It was working with Couchbase mobile, though...

I'll bet that in Couchbase Mobile you were either emitting the keys as arrays, or querying for strings. If you're still not sure, post the JavaScript map function you were using.

—Jens

dyowee

unread,
Aug 2, 2012, 5:58:41 PM8/2/12
to mobile-c...@googlegroups.com
I understand sir. I really appreciate your help.
Noong Huwebes, Agosto 02 2012 13:28:19 UTC+8, si Jens Alfke ay sumulat:
Reply all
Reply to author
Forward
0 new messages