seald / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
351 stars 32 forks source link

Option to use MongoDB like ID #43

Closed bacloud23 closed 9 months ago

bacloud23 commented 1 year ago

Is your feature request related to a problem? Please describe. Many apps I believe are based on the _id and how it is defined by MongoDB.

In my case for instance, I use it as the time of creation of documents. Directly in a query in order for instance to get documents by creation time.

function getObjectId(days) {
    const yesterday = new Date()
    days = days || 14
    yesterday.setDate(yesterday.getDate() - days)
    const hexSeconds = Math.floor(yesterday / 1000).toString(16)
    return new ObjectId(hexSeconds + '0000000000000000')
}
const objectId = getObjectId(days)
const query = {}
query._id = { $gt: objectId }

Describe the solution you'd like Add an option to use mongoDB ids

Describe alternatives you've considered I have no alternative other than adding createdAt field and change all my queries.

bacloud23 commented 1 year ago

My bad I totally ignored the option timestampData.. a bit of rework and it would be fine. feel free to close.