TransWikia.com

Sorting by timestamp doesn't provide accurate recent record

Stack Overflow Asked by user13599244 on November 16, 2021

I have indexed 64 bit Unix milliseconds timestamps. All of my MongoDB documents contain this timestamps.

Now, when I query like below, it doesn’t output most recent record. I’m not sure if this has to do with latency because even If I re-try after 2-3 seconds, it doesn’t output and yeah, It outputs if I try again like say 10 seconds or so.

let document = await table.find({ ip: ipAddress }).sort({timestamp: -1}).lean().limit(1).exec();

I stored live website session data on my database and each document weight around 5kb and my database running on Windows 2019 Server.

Actually, Both write and query happen same time but I expect write to be done faster as I use C++ for that part. Since I already tried after 2-3 seconds, it appear the latency is not the core issue.

Sample of Data can be seen below,

{
    "_id": {
        "$oid": "5f14cc1e283ea9705f1b31c2"
    },
    "userID": 1433571522,
    "ip": "135.114.236.220",
    "isNew": false,
    "receive_time": {
        "$numberLong": "1595198494512"
    },
    "event": "Click",
    "x": 93.39,
    "y": -492.00
}


{
    "_id": {
        "$oid": "5f14cc22283ea9705f1b31c3"
    },
    "userID": 1433571522,
    "ip": "135.114.236.220",
    "isNew": false,
    "receive_time": {
        "$numberLong": "1595198498608"
    },
    "event": "Press",
    "x": 91.39,
    "y": -20.00
}



{
    "_id": {
        "$oid": "5f14cc22283ea9705f1b31c4"
    },
    "userID": 1433571522,
    "ip": "135.114.236.220",
    "isNew": false,
    "receive_time": {
        "$numberLong": "1595198498652"
    },
    "event": "Type",
    "x": 11.24,
    "y": -29.00
}

I expect to have following result when I perform the above query,

{
    "_id": {
        "$oid": "5f14cc22283ea9705f1b31c4"
    },
    "userID": 1433571522,
    "ip": "135.114.236.220",
    "isNew": false,
    "receive_time": {
        "$numberLong": "1595198498652"
    },
    "event": "Type",
    "x": 11.24,
    "y": -29.00
}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP