Creating and querying a View


#1

When querying a view created through sync gateway admin interface, I got this error:

{
    "error": "Internal Server Error",
    "reason": "Internal error: error executing view req at http://127.0.0.1:8092/$DB/_design/admin/_view/qmunecards: 404 Object Not Found - {\"error\":\"not_found\",\"reason\":\"Design document _design/admin not found\"}\ "
}

I followed Creating and querying a view and I created a view through admin interface :4985 PUT /$DB/admin HTTP/1.1
with json:

{
    "views":{
        "qmunecards":{
            "map":"function (doc, meta) { if(doc.type === \"customer\"){ emit(doc.type, doc.test); } }"
        }
    }
}

With response HTTP Status Code 201 Created, and response body:

{"id": "admin","ok": true,"rev": "1-50b22d801b04fe3e48755ff1aa3b4926"}

Is there something wrong with my setup?


#2

Hi @JbalTero,

It looks like you’re missing the design document name in the PUT request, it should be :4985/dbname/_design/admin. For example, if the database is called todos:

PUT /todos/_design/admin HTTP/1.1
Content-Type: application/json
Host: localhost:4985
Connection: close
Content-Length: 136

{
	"views": {
		"qmunecards": {
			"map": "function (doc, meta) { if(doc.type === \"customer\"){ emit(doc.type, doc.test); } }"
		}
	}
}

And to query the view:

GET /todos/_design/admin/_view/qmunecards HTTP/1.1
Content-Type: application/json
Host: localhost:4985
Connection: close

James


#3

Oh Thanks. It works now.