Gathering detailed insights and metrics for mongoid-js
Gathering detailed insights and metrics for mongoid-js
Gathering detailed insights and metrics for mongoid-js
Gathering detailed insights and metrics for mongoid-js
@keystonejs/fields-mongoid
KeystoneJS MongoId Field Type
cqm-models
This library contains auto generated Mongo (Mongoose.js) models that correspond to the QDM (Quality Data Model) specification.
rails_admin
RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.
mongoid
generate mongo objectids, turn hex strings into objectids
npm install mongoid-js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
4 Stars
84 Commits
3 Forks
2 Watching
5 Branches
1 Contributors
Updated on 07 Jul 2023
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
10.8%
514
Compared to previous day
Last week
2.8%
3,471
Compared to previous week
Last month
16.3%
14,056
Compared to previous month
Last year
-3.6%
120,340
Compared to previous year
very very fast MongoID compatible unique id generator
Generates unique id strings. The ids are constructed like MongoDB document ids,
built out of a timestamp, system id, process id and sequence number. Similar
to BSON.ObjectID()
, but at 12 million ids / sec, 35 x faster.
The ids are guaranteed unique on any one server, and can be configured to be unique across a cluster of up to 16 million (2^24) servers. Uniqueness is guaranteed by unique {server, process} id pairs.
The ids returned by an id factory are always in strictly ascending order;
an id string will compare as <
less than any id string generated after it.
The uniqueness guarantee requires that process ids be no more than 16 bits
(kernel.pid_max
must be configured to 65535 or less on linux).
The 24-char id string is constructed by concatenating the big-endian hex values of
var mongoid = require('mongoid-js');
var id = mongoid(); // => "543f376340e2816497000001"
var id2 = mongoid(); // => "543f376340e2816497000002"
var MongoId = require('mongoid-js').MongoId;
var idFactory = new MongoId(/*systemId:*/ 0x123);
var id = idFactory.fetch(); // => "543f3789001230649f000001"
generates ids that are unique to this server. The ids are generated by a
new MongoId
singleton initialized with a random machine id. All subsequent calls
to mongoid()
in this process will fetch ids from this singleton.
// ids with a randomly chosen system id (here 0x40e281)
var mongoid = require('mongoid-js');
var id1 = mongoid(); // => "543f376340e2816497000001"
var id2 = mongoid(); // => "543f376340e2816497000002"
Create an id factory that embeds the given system id in each generated unique id. By a systematic assignment of system ids to servers, this approach can guarantee globally unique ids (ie, globally for an installation).
The systemId must be an integer between 0 and 16777215 (0xFFFFFF), inclusive. If no system id is specified, a random 24-bit integer is used.
// ids with a unique system id (here 0xbaabaa)
var MongoId = require('mongoid-js').MongoId;
var systemId = 0xBaaBaa;
var idFactory = new MongoId(systemId);
idFactory.fetch(); // => "59cd11d3baabaa05ce000001"
MongoId objects can act as id factories. Each factory can also assign itself an id,
done the first time it is converted toString
.
Id factories should all have unique system ids, else they may not generate unique ids.
var MongoId = require('mongoid-js').MongoId;
var systemId = 0x123456;
var ids = new MongoId(systemId);
generate and return the next id in the sequence. Up to 16 million distinct ids (16777216) can be fetched during the same wallclock second; trying to fetch more blocks until the next second. The second starts when the clock reads *000 milliseconds, not when the first id is fetched. The second ends 1000 milliseconds after the start, when the clock next reads *000 milliseconds.
var ids = new MongoId(0x001230);
var id1 = ids.fetch(); // => "543f3789001230649f000001"
var id2 = ids.fetch(); // => "543f3789001230649f000002"
var id3 = ids.fetchShort(); // => "K2wrXF-HB5HU---2"
var id4 = ids.fetch(); // => "543f3789001230649f000004"
return the next id in the sequence, encoded to be more compact. The id itself is the same as
returned by fetch()
, but expressed as a shorter string. Shortids can be converted to and
from ordinary hexids; see shorten
and unshorten
below. Note that the parse
and related
functions operate on hexids.
With no idString
, parse the factory's (id object's) built-in id. If the factory does not
yet have an id string, assign one. Same as MongoId.parse(id.toString())
, see below. If
idString
is provided, parse it just like MongoId.parse
.
Get the timestamp of the id factory itself. Assign a new id string to the factory if it
does not yet have one. Same as MongoId.getTimestamp(id.getTimestamp())
, see below.
Return the factory id string. If the factory does not yet have an id string, assign one. The assigned id is reused the next time it a factory id is needed.
var ids = new MongoId();
var id1 = ids.fetch(); // => "59cd101bd5057e7ec1000001"
ids.toString(); // => "59cd101bd5057e7ec1000002"
Decompose the id string into its parts -- unix timestamp, machine id,
process id and sequence number. Unix timestamps are seconds since the
start of the epoch (1970-01-01 GMT). Note that parse()
returns seconds,
while getTimestamp()
returns milliseconds.
var parts = MongoId.parse("543f376340e2816497000013");
// => { timestamp: 1413429091, // 0x543f3763
// machineid: 4252289, // 0x40e281
// pid: 25751, // 0x6497
// sequence: 19 } // 0x000013
Return just the javascript timestamp part of the id. Javascript timestamps are milliseconds since the start of the epoch. Each mongoid embeds a seconds precision unix timestamp; getTimestamp() returns that multiplied by 1000.
MongoId.getTimestamp("543f376340e2816497000013");
// => 1413429091000
Convert the hexadecimal mongoid to a more compact string. The conversion is lossless. The converted strings sort into the same respective alpha order as in hexadecimal form, and are safe to use in URLs.
Convert the shortened mongoid string back to its hexadecimal form.
MongoId.shorten("543f376340e2816497000013");
// => "K2wrNo2XVLHM---I"
MongoId.unshorten("K2wrNo2XVLHM---I");
// => "543f376340e2816497000013"
Redefine the shortid character set. charset
is expected to be a string of 64 7-bit ASCII characters.
The default character set is -
, 0-9
, A-Z
, _
, and a-z
, in that order (ASCII order).
The character set 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
would
produce base64 shortids (which wouldn't sort into timestamp and sequence order, but would be
base64). Note that this changes the shortid charset globally, for all MongoId instances.
fetchShort()
and setShortCharset
, optional hexid to id.parse(), 25% faster fetch()shorten
and unshorten
, block until next second if out of ids (do not throw)qnit
dev dependency into .travis.ymlbrowserify
support: use a random pid if process.pid is not set, avoid object methods in constructor, 100% unit test coverageNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More