1

I am trying to search couchdb with nano, as described here:

https://github.com/dscape/nano#dbsearchdesignname-searchname-params-callback

But I get 'document is missing attachment'.

var config = require('./config.js');
var nano = require('nano')(config.dbhost);

var couch = nano.db.use('my-database');

couch.search('object-views', 'by-content', {q: 'hello'}, function(err, data) {
    if(err) {
        console.log('ERROR ', err);
    } else {
        console.log(data);
    }
})

EDIT this is my view code:

function (doc) {
  if(doc.type && doc.type==='message') {
    emit(doc.text.toLowerCase(), 1);
  }
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
user4893295
  • 533
  • 6
  • 25
  • Do you have a design document named `_design/object-views` with the following map function : `by-content` ? – Alexis Côté Nov 15 '17 at 03:39
  • Yes I do @AlexisCôté and if I change 'search' to 'view' it pulls the data fine. Is there something I need to do to the view to make it work? I'll edit the question with my view code – user4893295 Nov 15 '17 at 10:47

1 Answers1

1

So I looked inside nano code and found that the search is designed for Cloudant only. It calls a view of type "search".

So instead of calling _designdoc/name/_view/something, it calls:

_designdoc/name/_search/something

So basically, use db.view

Alexis Côté
  • 3,670
  • 2
  • 14
  • 30
  • Ah, that would be why then! So how does one do a text search, eg match 'this is to test search' from search string 'test'? – user4893295 Nov 15 '17 at 15:03
  • I think that _search is basically a text index (where you can search anything). As for the _view, it's simply map/reduce functions that you define – Alexis Côté Nov 15 '17 at 15:11