Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Monk is a tiny layer that provides simple yet substantial usability improvements for MongoDB usage within Node.JS.
var db = require('monk')('localhost/mydb')
, users = db.get('users')
users.index('name last');
users.insert({ name: 'Tobi', bigdata: {} });
users.find({ name: 'Loki' }, '-bigdata', function () {
// exclude bigdata field
});
findAndModify
supports the
update
signature style)_id
in queriesvar db = require('monk')('localhost/mydb')
var db = require('monk')('localhost/mydb,192.168.1.1')
var users = db.get('users')
// users.insert(), users.update() … (see below)
users.drop(fn);
data[, …], fn
. For example
find({}, fn)
findOne({}, fn)
update({}, {}, fn)
findAndModify({}, {}, fn)
findById('id', fn)
data[, …], options, fn
data[, …], ['field', …], fn
data[, …], 'field1 field2', fn
data[, …], '-field1', fn
All methods that perform an async action return a promise.
var promise = users.insert({});
promise.type; // 'insert' in this case
promise.error(function(err){});
promise.on('error', function(err){});
promise.on('success', function(doc){});
promise.on('complete', function(err, doc){});
promise.success(function(doc){});
users.index('name.first', fn);
users.index('email', { unique: true }); // unique
users.index('name.first name.last') // compound
users.index({ 'email': 1, 'password': -1 }); // compound with sort
users.index('email', { sparse: true }, fn); // with options
users.indexes(fn); // get indexes
users.dropIndex(name, fn); // drop an index
users.dropIndexes(fn); // drop all indexes
users.insert({ a: 'b' }, function (err, doc) {
if (err) throw err;
});
To cast to ObjectId
:
users.id('hexstring') // returns ObjectId
users.id(obj) // returns ObjectId
users.update({}, {}, fn);
users.updateById('id', {}, fn);
users.find({}, function (err, docs){});
users.findById('hex representation', function(err, doc){});
users.findById(oid, function(err, doc){});
findOne
also provides the findById
functionality.
users.findOne({ name: 'test' }).on('success', function (doc) {});
users.findAndModify({ query: {}, update: {} });
users.findAndModify({ _id: '' }, { $set: {} });
Note: stream: true
is optional if you register an each
handler in the
same tick. In the following example I just include it for extra clarity.
users.find({}, { stream: true })
.each(function(doc){})
.error(function(err){})
.success(function(){});
If you wish to see what queries monk
passes to the driver, simply leverage
debug:
DEBUG="monk:queries"
To see all debugging output:
DEBUG="monk:*"
(The MIT License)
Copyright (c) 2012 Guillermo Rauch <guillermo@learnboost.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0.1.4 / 2012-05-06
insert
resolves promise in next tick.FAQs
The wise MongoDB API
The npm package monk receives a total of 3,474 weekly downloads. As such, monk popularity was classified as popular.
We found that monk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.