Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to query views #4

Open
ghost opened this issue Jul 7, 2016 · 8 comments
Open

Unable to query views #4

ghost opened this issue Jul 7, 2016 · 8 comments

Comments

@ghost
Copy link

ghost commented Jul 7, 2016

Hi,

After seeding the ddocs, and seeing a 'ddocs updated!' message in the console, when I try to query it throws a NotFoundError with ddoc books has no view named byTitle.

db.query('books/byTitle', { key: title })
.then(function(result) {
    console.log(result) 
}).catch(function(err){
    console.log(err)
})

When I examine the _design/books object in the IndexedDB through chrome dev tools, I can see that the view does actually exist.

Thought it might be related to nolanlawson/pouchdb-find#163 - but I am never able to get it working, even after a refresh/second query.

Any ideas?

Thanks

@ghost
Copy link
Author

ghost commented Jul 7, 2016

I should note that I'm trying to use this inside of a frontend React app, interacting with a local database... Is this meant to be used with a remote db only, or something?

@colinskow
Copy link
Owner

colinskow commented Jul 8, 2016

@paulinder this is due to a breaking change that I accidentally introduced in the latest version. This will be fixed soon. Meanwhile you need to add a map object to each view:

var ddoc = {
 person: {
   views: {
     byFirstName: { map: function (doc) {
       emit(doc.firstName);
     } },
     byLastName: { map: function (doc) {
       emit(doc.lastName);
     } },
     byFullName: { map: function (doc) {
       emit(doc.firstName + ' ' + doc.lastName);
     } }
   }
 }
};

Apologies!!!

@ghost
Copy link
Author

ghost commented Jul 8, 2016

Thanks for your quick reply - very helpful.

I think you meant to have switched each map with each view name. For example, byFirstName and the corresponding map should be switched.

I was able to get some results by making this change. Thank you.

@ghost ghost closed this as completed Jul 8, 2016
@colinskow
Copy link
Owner

Yup :-) I'm going to keep this open until it is fixed. Next release you won't need to add map.

@colinskow colinskow reopened this Jul 8, 2016
@tohagan
Copy link

tohagan commented Jul 15, 2016

Each view needs both map and optional reduce properties. Not supporting reduce would be a bug.

So I think the map is still needed. Yes?

You could make map optional (replacing myview: function() ... with myview: { map: function() ... }) but IMHO think this complicates the API.

Note: If you kept map and reduce you'd need to update user-design.js code in superlogin.

So in summary I'd say the only bug is the documentation (README and example code) and that keeping map is just fine.

@colinskow
Copy link
Owner

Yes, I'm going to fix this up very soon so it works exactly as specified in the documentation. There was no test for this, so I accidentally broke it last release.

@tohagan
Copy link

tohagan commented Jul 19, 2016

Just a tad confused by this last comment ... So I think what you said was that the existing docs are correct and you therefore won't be supporting reduce views? Was hoping to use reduce views in a current project but so I'd be forced to fork and fix up my own which I'd rather avoid. Can you please clarify if you're supporting the reduce property.

@AnasMunir
Copy link

hi @colinskow is the bug fixed yet in pouchdb?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants