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

Provide a way to set MACHINE_ID #10

Closed
stalniy opened this issue Sep 9, 2017 · 2 comments
Closed

Provide a way to set MACHINE_ID #10

stalniy opened this issue Sep 9, 2017 · 2 comments

Comments

@stalniy
Copy link

stalniy commented Sep 9, 2017

I'm working on cordova based application and want to generate ObjectId in browser. From source code I see that MACHINE_ID is a random number and it means that I potentially may have issues when 2 clients of my application generate the same ObjectId.

In order to overcome this issue I could use cordova-plugin-device, retrieve uuid and use it as MACHINE_ID. That way I will make sure that all my clients generate unique ObjectIds.

Alternatevely it's possible to use userId as MACHINE_ID which is provided by my API.

I can create a PR if you are ok with suggestion:

import ObjectId from 'bson-objectid'

ObjectId.setMachineId(device.uuid)
@williamkapke
Copy link
Collaborator

williamkapke commented Sep 9, 2017

timestamp+machineid+programid+counter produces an amazing amount of entropy so collisions would be pretty phenomenal.

... but, if folks want to specify a machine id- sure they can use it at their own risk! setMachineId will just need to validate that the input is an int. Just know that it will truncate that int to the last 6 hex chars. (That mirrors how the bson lib works)

PRs always welcome!

@stalniy
Copy link
Author

stalniy commented Sep 9, 2017

In browser MACHINE_ID will be regenerated each time user open/close application, that's why I want to ensure that it's a static unique number for this user which doesn't change

Update:
Cool! I will work on PR tomorrow :)

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

2 participants