techfort / LokiJS

javascript embeddable / in-memory database
http:/techfort.github.io/LokiJS
MIT License
6.73k stars 482 forks source link

What's wrong with the the 'fun is not a function' ? #816

Closed youyinnn closed 4 years ago

youyinnn commented 4 years ago

perform in .find({ name: name })

nshCore commented 4 years ago

@youyinnn If you have a solution to this problem maybe you could update the issue so other people like me can find it :D

youyinnn commented 4 years ago

@nshCore hi, I fixed this problem by finding out a mistake of my code.

when it was performing the function .find({ name: name }), the value name should be a basic type like number or string or boolean, while in my wrong case, I was passing an object name in it, so I got the error log like:

D:\Workshop\MyNodejs\node_modules\lokijs\src\lokijs.js:3519
              if (fun(t[i][property], value)) {
                  ^

TypeError: fun is not a function
    at Resultset.find (D:\Workshop\MyNodejs\node_modules\lokijs\src\lokijs.js:3519:19)
    at Collection.find (D:\Workshop\MyNodejs\node_modules\lokijs\src\lokijs.js:6797:27)
    at runProgramLogic (D:\Workshop\MyNodejs\practices\lokijs\core.js:41:20)
    at databaseInitialize (D:\Workshop\MyNodejs\practices\lokijs\core.js:18:5)
    at D:\Workshop\MyNodejs\node_modules\lokijs\src\lokijs.js:2626:15
    at loadDatabaseCallback (D:\Workshop\MyNodejs\node_modules\lokijs\src\lokijs.js:2542:15)
    at readFileCallback (D:\Workshop\MyNodejs\node_modules\lokijs\src\lokijs.js:2348:15)
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61:3)

so if you got this error please use the basic type values as keys to index your record:

result = users.find({
    name: 'mike'
});

instead of:

result = users.find({
    name: { name: 'mike' }
});