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

Any method for unique id generator ? #201

Open
aswathshobi opened this issue Jun 28, 2021 · 5 comments
Open

Any method for unique id generator ? #201

aswathshobi opened this issue Jun 28, 2021 · 5 comments

Comments

@aswathshobi
Copy link

No description provided.

@EtzBetz
Copy link
Contributor

EtzBetz commented Aug 16, 2021

Yea, I'm missing this. When I originally found the lib, I thought that by array support and index searching, it was meant that I could push elements into an array and have them assigned an incrementing id automatically. Since there is also a function getIndex(), which kinda does the other part of that workflow, that's even more of a bummer..

I guess I'll need to build my own index-builder around this now :/

@PointSingularity
Copy link

Maybe it is not suitable for your needs, but with newer Node versions you can generate v4 UUIDs natively with no need for additional packages.

Fun fact, even browsers have their own crypto global object with similar functionality.

@EtzBetz
Copy link
Contributor

EtzBetz commented Dec 16, 2021

Maybe it is not suitable for your needs, but with newer Node versions you can generate v4 UUIDs natively with no need for additional packages.

Uh, that's nice to hear. One less dependency for me. What I would find more interesting to have is if the library itself would work with uuids or similar internally, without us needing to incorporate somehow.

@PointSingularity
Copy link

Yeah, that would definitely be a nice utility feature to have.

@kgDG12
Copy link

kgDG12 commented Jun 29, 2022

I found this temporary solution , we can call this function when creating something
it worked for me...

const ObjectId = (m = Math, d = Date, h = 16, s = s => m.floor(s).toString(h)) =>
  s(d.now() / 1000) + ' '.repeat(h).replace(/./g, () => s(m.random() * h))

Like this

db.push("/users[]", {
    _id: ObjectId(),
    username: username
  }, true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants