Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong result while quering by $lt/lte/gte with a large numeric string property #910

Open
qiangbro opened this issue Mar 1, 2022 · 1 comment
Labels

Comments

@qiangbro
Copy link

qiangbro commented Mar 1, 2022

my code:

    let t;

    let alarms = [];
    for (let i = 0; i < 80000; i++) {
        let id = "74590869096" + (907836 + i);
        alarms.push({id, name: 'hello' + i});
    }

    var db = new loki('exampleDB');
    var alarmCollection = db.addCollection('myAlarms', {unique: ['id']});

    t = Date.now();
    alarms.forEach(obj => alarmCollection.insert(obj));
    console.log(`完成插入 耗时${(Date.now() - t) / 1000}s alarmCollection.count=${alarmCollection.count()}`);


    let example = alarmCollection.chain().compoundsort(['id']).offset(50000).limit(1).data()[0];
    let exampleId = example.id;

    console.log('exampleId', exampleId)

    t = Date.now();
    console.log('count jlt exampleId by lokijs',  alarmCollection.count({id: {$jlt: exampleId}}), `, 耗时${(Date.now() - t) / 1000}s`);
    t = Date.now();
    console.log('count jlte exampleId by lokijs', alarmCollection.count({id: {$jlte: exampleId}}), `, 耗时${(Date.now() - t) / 1000}s`);
    t = Date.now();
    console.log('count jgt exampleId by lokijs',  alarmCollection.count({id: {$jgt: exampleId}}), `, 耗时${(Date.now() - t) / 1000}s`);

    t = Date.now();
    console.log('count lt exampleId by js',    alarms.filter(a => (a.id < exampleId)).length, `, 耗时${(Date.now() - t) / 1000}s`);
    t = Date.now();
    console.log('count lte exampleId by js',    alarms.filter(a => (a.id <= exampleId)).length, `, 耗时${(Date.now() - t) / 1000}s`);
    t = Date.now();
    console.log('count gt exampleId by js',    alarms.filter(a => (a.id > exampleId)).length, `, 耗时${(Date.now() - t) / 1000}s`);

    t = Date.now();
    console.log('count lt exampleId by lokijs',  alarmCollection.count({id: {$lt: exampleId}}), `, 耗时${(Date.now() - t) / 1000}s`);
    t = Date.now();
    console.log('count lte exampleId by lokijs', alarmCollection.count({id: {$lte: exampleId}}), `, 耗时${(Date.now() - t) / 1000}s`);
    t = Date.now();
    console.log('count gt exampleId by lokijs',  alarmCollection.count({id: {$gt: exampleId}}), `, 耗时${(Date.now() - t) / 1000}s`);

result:

完成插入 耗时0.101s alarmCollection.count=80000
exampleId 74590869096957836
count jlt exampleId by lokijs 50000 , 耗时0.005s
count jlte exampleId by lokijs 50001 , 耗时0.005s
count jgt exampleId by lokijs 29999 , 耗时0.004s
count lt exampleId by js 50000 , 耗时0.002s
count lte exampleId by js 50001 , 耗时0.002s
count gt exampleId by js 29999 , 耗时0.002s
count lt exampleId by lokijs 49997 , 耗时0.018s
count lte exampleId by lokijs 50012 , 耗时0.015s
count gt exampleId by lokijs 29988 , 耗时0.016s

as we can see, count lte exampleId shoud be 50001, es6 and $jlte return correct result, but lokijs's $lte returns 50012.

@qiangbro qiangbro changed the title Wrong result while quering by $lt/lte/gte with a large numeric string Wrong result while quering by $lt/lte/gte with a large numeric string property Mar 1, 2022
@stale
Copy link

stale bot commented May 1, 2022

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.

@stale stale bot added the wontfix label May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant