techfort / LokiJS

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

Querying objects with dot notation fails with error: TypeError: Cannot use 'in' operator to search for 'b' in null #891

Closed olmuz closed 2 years ago

olmuz commented 2 years ago

Querying objects with dot notation fails if there is an object with null value

Steps to reproduce:

const Loki = require('lokijs');
const db = new Loki();

const coll = db.addCollection('myCollection');

coll.insert({ a: { b: 'c' } });
coll.insert({ a: null });

coll.find({ 'a.b': 'c' });

Error:

/node_modules/lokijs/src/lokijs.js:418
      if (typeof root === 'object' && path in root) {
                                           ^

TypeError: Cannot use 'in' operator to search for 'b' in null

LokiJS version - 1.5.12

blaky commented 2 years ago

My PR should fix it: https://github.com/techfort/LokiJS/pull/896

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.