
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
moment-objectid
Advanced tools
Format a moment instance as ObjectID-string for use in MongoDB queries
Format a moment
instance as ObjectId-string for use in MongoDB queries.
As per spec an ObjectId
contains a timestamp as the first eight bytes.
Think of it this way: the _id
field in MongoDB already contains a createdAt
timestamp. Yay. And it's already indexed. Double yay!
This module extends the Moment
prototype and adds a new toObjectId
method. Note that it returns a string
, not an instance of ObjectId
(because this depends on the driver you use).
First do a npm install moment-objectid
. Then require
and execute it (the module returns a function).
//Patch the moment prototype.
require('moment-objectid')();
Note: moment-objectid
does not list moment
as dependency, because then it would only patch its own dependency and not necessarily the moment
you use in your code.
Example using Mongoose (if you're not using Mongoose, you need to wrap the returned string in a ObjectId
. Mongoose does that for us.).
var moment = require('moment');
//All posts from October 2012.
var query = {
_id: {
$gte: moment('2012-10-01').toObjectId(),
$lte: moment('2012-10-01').endOf('month').toObjectId()
}
};
BlogPost.find(query).exec(function(err, posts) {
//Do stuff with the posts. Or don't. I'm not telling you how to live your life.
});
FAQs
Format a moment instance as ObjectID-string for use in MongoDB queries
The npm package moment-objectid receives a total of 0 weekly downloads. As such, moment-objectid popularity was classified as not popular.
We found that moment-objectid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.