couchdb-nano
couchdb-nano copied to clipboard
Referer header required
Code:
export abstract class CouchDbService {
private readonly connection = nano(Utils.CouchDbUrlAuth);
private readonly db: DocumentScope<string>;
constructor(dbName: DB) {
this.db = this.connection.use(dbName);
}
...
let mangoQuery = {
selector: {
_id: {$exists: true}
},
fields: ["_id"],
limit: 50
};
this.db.find(mangoQuery);
Expected Behavior
Successful response
Current Behavior
{
"message": "Referer header required.",
"stack": "Error: Referer header required. at Request._callback (*\node_modules\nano\lib\nano.js:154:15) at Request.self.callback (*\node_modules\request\request.js:185:22) at Request.emit (events.js:189:13) at Request.EventEmitter.emit (domain.js:441:20) at Request.<anonymous> (*\node_modules\request\request.js:1161:10) at Request.emit (events.js:189:13) at Request.EventEmitter.emit (domain.js:441:20) at IncomingMessage.<anonymous> (*\node_modules\request\request.js:1083:12) at Object.onceWrapper (events.js:277:13)",
"name": "Error",
"error": "bad_request",
"reason": "Referer header required.",
"scope": "couch",
"statusCode": 400,
"request": {
"method": "POST",
"headers": {
"content-type": "application/json",
"accept": "application/json"
},
"uri": "http://XXXXXX:XXXXXX@***/***/_find",
"body": "{"selector":{"_id":{"$exists":true}},"fields":["_id"],"limit":50}",
"qsStringifyOptions": {
"arrayFormat": "repeat"
}
},
"headers": {
"uri": "http://XXXXXX:XXXXXX@***/***/_find",
"statusCode": 400,
"date": "Mon, 29 Apr 2019 17:06:54 GMT",
"content-type": "application/json",
"cache-control": "must-revalidate"
},
"errid": "non_200",
"description": "couch returned 400"
}
Possible Solution
hz
Context
Trying to make search in CouchDB with MongoBD syntax;
Your Environment
- Version used: 8.0.1
- Browser Name and version: ?
- Node: v10.15.3
- Operating System and version (desktop or mobile): Windows 10
- Link to your project: Proprietary
I'm getting the same via the homebrew installation with the following code:
export async function getUserByEmail(email: string): Promise<IUser> {
const users = nano.use('users')
const resp = await users.find({
fields: ["emails"],
selector: {
emails: {
$elemMatch: {
$eq: email,
},
},
},
});
// ...
}
any solution? i'm getting the same error. async function find() { try { const dbMobile = mobileNano.db.use("myDb"); const data = await dbMobile.find({ params: { selector: { "|type": "user", }, }, }); console.log("dd", data); } catch (error) { console.log("Error: ", error); } }