Using the pouchdb-find plugin, when I call db.createIndex, I get the following error:
TypeError: db.fetch is not a function
at dbFetch (/home/moses/dev/safecontracts/backend/accounts-app/node_modules/pouchdb-find/lib/index.js:46:6)
at createIndex (/home/moses/dev/safecontracts/backend/accounts-app/node_modules/pouchdb-find/lib/index.js:63:3)
at PouchDB.<anonymous> (/home/moses/dev/safecontracts/backend/accounts-app/node_modules/pouchdb-find/lib/index.js:1371:3)
at /home/moses/dev/safecontracts/backend/accounts-app/node_modules/pouchdb-utils/lib/index.js:118:21
at new Promise (<anonymous>)
at PouchDB.<anonymous> (/home/moses/dev/safecontracts/backend/accounts-app/node_modules/pouchdb-utils/lib/index.js:105:19)
at PouchDB.createIndex (/home/moses/dev/safecontracts/backend/accounts-app/node_modules/argsarray/index.js:14:18)
[鈥
console.log(db.fetch) gives undefined.
Maybe, you have to initialize it properly? In my case, the following works:
import PouchDB from 'pouchdb';
import PouchDBFind from 'pouchdb-find';
PouchDB.plugin(PouchDBFind);
@AntonPilyak I require the packages because I'm in Node, but otherwise I do the same. Thanks though.
Reading the pouchdb-find code, I can't even tell how the fetch method is supposed to get attached to PouchDB, so it's really hard to debug.
Oops, I'm an idiot. I didn't notice the plugin was on different major version (v7.0) than Pouch itself (v6.4). Solved.
For my own reference
package.json:
"pouchdb": "^6.4.3",
"pouchdb-find": "^6.4.3",
// not @types/pouchdb
// not @types/pouchdb-find
tsconfig.json:
"compilerOptions": {
"typeRoots": [
"./typings",
add 2 subfolders to the typings folder named pouchdb and pouchdb-find, each containing an index.d.ts file containing the line declare module 'pouchdb'; or declare module 'pouchdb-find';.
client side node:
import PouchDB from 'pouchdb'
import PouchFind from 'pouchdb-find'
myClientDb: any; // not PouchDB.Database
constructor(){PouchDB.plugin(PouchFind)}
server side node:
import PouchDB = require('pouchdb')
import PouchFind = require('pouchdb-find')
myServerDb: any; // not PouchDB.Database
constructor(){PouchDB.plugin(PouchFind)}
Most helpful comment
Oops, I'm an idiot. I didn't notice the plugin was on different major version (v7.0) than Pouch itself (v6.4). Solved.