Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
access-mongo
Advanced tools
Readme
Simple MongoDB wrapper. Will present a consistent promised API for both MongoDB and NEDB databases.
This will be incredibly useful for testing using local files rather than actual MongoDB instances. This will also be very useful for using a MongoDB-like database for work that can use simple flat files. In this case your fixtures can just be the NEDB files, which are an extended form of JSON.
npm install --save access-mongo
var AccessMongo = require('access-mongo');
AccessMongo.connect('mongodb://foo:bar@hello.com:1234/mydb').then(function() {
// create a model for collection users
var User = AccessMongo.createModel('users');
User.where({name: 'Matt'}).then(function(user) {
console.log(user);
});
});
// connect to multiple databases
AccessMongo.connect({
foo: 'mongodb://foo:bar@hello.com:1234/mydb',
bar: 'mongodb://foo:bar@yoyo.foo.bar:1234/otherdb'
}).then(function() {
var FooUser = AccessMongo.createModel('users', {connection: 'foo'});
var BarUser = AccessMongo.createModel('users', {connection: 'foo'});
});
// override query parameters of all connections
AccessMongo.connect({
foo: 'mongodb://foo:bar@hello.com:1234/mydb',
bar: 'mongodb://foo:bar@yoyo.foo.bar:1234/otherdb'
}, {
maxPoolSize: 3
});
// create an nedb database
AccessMongo.connect('test.db').then(function() {
var User = AccessMongo.createModel('users');
User.where({name: 'Matt'}).then(function(user) {
console.log(user);
});
});
AccessMongo
is a singleton that manages the connection state to each database you connect to. You can connect to one or multiple databases. Each connection has a name that you can use to refer to it later. If you don't specify a name the connection name will be default
.
Returns a promise that resolves to the instance of AccessMongo
.
AccessMongo.connect('mongodb://localhost:27017/test-db');
Returns a promise that resolves to the instance of AccessMongo
.
AccessMongo.connect({
default: 'mongodb://localhost:27017/test-db',
foo: 'mongodb://foo:bar@other.db.com:27019/some-db'
});
Returns a promise that resolves to the instance of AccessMongo
.
AccessMongo.disconnect();
Returns a Model
object.
// create a model stored in the 'users' collection
var User = AccessMongo.createModel('users');
// create a model stored in the 'users' collection, 'foo' connection, default database
var User = AccessMongo.createModel('users', {connection: 'foo'});
// create a model stored in the 'users' collection, 'default' connection, 'other-db' database
var User = AccessMongo.createModel('users', {database: 'other-db'});
// create a model stored in the 'users' collection, 'foo' connection, 'other-db' database
var User = AccessMongo.createModel('users', {connection: 'foo', database: 'other-db'});
// create a query
var query = User.where({name: 'Matt Insler'});
// add to a query
query.where({email: 'matt.insler@gmail.com'});
// skip
User.skip(5);
User.where({...}).skip(5);
// limit
// fields
User.fields({name: 1, address}); // only include name and address
User.where({...}).fields({timestamp: 0}); // omit timestamp
// sort
User.sort({name: 1}); // sort by name ascending
User.where({...}).sort({name: -1}); // sort by name descending
// fetch the first document matching this query
User.first().then(function(user) {
});
User.where({...}).then(function(user) {
});
// fetch all documents matching this query
User.array().then(function(users) {
});
User.where({...}).array().then(function(users) {
});
// Create a cursor for this query
var cursor = User.cursor();
var cursor = User.where({...}).cursor();
// Count the documents matching this query
User.count().then(function(count) {
});
User.where({...}).count().then(function(count) {
});
// Get a list of distinct values of the field matching this query
User.distinct('name').then(function(distinctNames) {
});
User.where({...}).distinct('name').then(function(distinctNames) {
});
// Insert a document, will not update
User.create({...}).then(function(savedDocument) {
);
// Insert multiple documents, will not update
User.create([{...}, {...}]).then(function(arrayOfSavedDocuments) {
);
// Save a document, doing an update if the document has an '_id' field, and an insert if not
User.save({...}).then(function(savedDocument) {
});
// Update a single document matching the query
// options: http://mongodb.github.io/node-mongodb-native/1.4/api-generated/collection.html#update
User.update(query, update, options).then(function(numDocumentsChanged, details) {
// check details.updatedExisting to see if objects were inserted or updated (when using {upsert: true})
});
// Update a single document matching the query from the where({...})
User.where({...}).update(update, options).then(function(numDocumentsChanged, details) {
});
User.where({...}).firstAndUpdate(update, options).then(function(fetchedDocument) {
});
// To prevent you from removing all documents by accident, this will throw an Error
User.remove();
// To remove all documents you can override this failsafe
User.remove({ override: true });
// Remove all documents matching this query
User.where({...}).remove().then(function(numDocumentsRemoved) {
});
Returns the default connection object if there is a one or null
.
This is the equivalent of AccessMongo.getConnection('default')
.
var connection = AccessMongo.getDefaultConnection();
Returns the connection object by name or null
.
var connection = AccessMongo.getConnection('foo');
var db = connection.getDefaultConnection();
var db = connection.getDatabase('my-db');
connection.disconnect();
var collection = db.getCollection('users');
Copyright (c) 2015 Matt Insler Licensed under the MIT license.
FAQs
Simple MongoDB wrapper
We found that access-mongo 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.
Research
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.