CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mongoskin

A simplified wrapper layer above the node-mongodb-native driver that provides a streamlined API for MongoDB database operations

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Mongoskin

Mongoskin is a JavaScript wrapper library that provides a simplified and enhanced API layer on top of the official MongoDB Node.js driver (node-mongodb-native). It offers callback-based operations with lazy connection handling, convenient helper methods, and streamlined connection management to reduce boilerplate code while maintaining compatibility with the underlying MongoDB driver's API.

Package Information

  • Package Name: mongoskin
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install mongoskin

Core Imports

const mongoskin = require('mongoskin');

Basic Usage

const mongoskin = require('mongoskin');

// Connect to database using connection string
const db = mongoskin.db('mongodb://localhost:27017/myapp');

// Bind collections for easy access
db.bind('users');
db.bind('posts');

// Use enhanced collection methods
db.users.findById('507f1f77bcf86cd799439011', (err, user) => {
  if (err) throw err;
  console.log(user);
});

// Insert and find with simplified API
db.posts.insert({ title: 'Hello World', author: 'Alice' }, (err, result) => {
  if (err) throw err;
  
  db.posts.findItems({ author: 'Alice' }, (err, posts) => {
    if (err) throw err;
    console.log(posts);
    db.close();
  });
});

Architecture

Mongoskin implements a "Skin" class pattern where each MongoDB native class gets a corresponding wrapper:

  • Lazy Connection Pattern: Methods can be called before connection is established; connection opens automatically when needed
  • State Management: Tracks connection state (CLOSE, OPENING, OPEN) for efficient resource management
  • API Compatibility: All native MongoDB driver methods are proxied through to underlying instances
  • Enhanced Methods: Additional convenience methods layered on top of standard MongoDB API
  • Event-driven: Uses EventEmitter pattern for connection lifecycle management

Capabilities

Database Connection

Core database connection functionality with lazy connection management and enhanced connection methods.

function db(connectionString, options): SkinDb;

class MongoClient {
  static connect(connectionString, options, callback): SkinDb;
}

Database Connection

Collection Operations

Enhanced collection interface with convenience methods for common database operations, including findById, updateById, and removeById.

class Collection {
  find(query, options, callback): SkinCursor;
  findItems(query, options, callback): Collection;
  findEach(query, options, eachCallback): Collection;
  findById(id, callback): Collection;
  updateById(id, doc, callback): Collection;
  removeById(id, callback): Collection;
  bind(extendObject): void;
}

Collection Operations

Query and Cursor Management

Cursor operations for iterating through query results with automatic connection handling.

class Cursor {
  toArray(callback): void;
  each(callback): void;
  next(callback): void;
  limit(limit): Cursor;
  skip(skip): Cursor;
  sort(sort): Cursor;
}

Query and Cursor Management

Administrative Operations

Database administration capabilities including user management, indexing, and server statistics.

class Admin {
  listDatabases(callback): void;
  serverStatus(callback): void;
  addUser(username, password, options, callback): void;
  removeUser(username, callback): void;
}

Administrative Operations

GridFS File Storage

GridFS operations for storing and retrieving large files in MongoDB with streaming support.

class GridStore {
  static exist(db, name, callback): void;
  static list(db, callback): void;
  static read(db, name, callback): void;
  static readlines(db, name, callback): void;
  static unlink(db, name, callback): void;
  open(mode, callback): void;
  write(data, callback): void;
  close(callback): void;
}

GridFS File Storage

Utilities and Helpers

Helper functions for common MongoDB operations including ObjectID conversion and validation.

const helper = {
  toObjectID(hex): ObjectID;
  isObjectID(idstr): boolean;
};

const utils = {
  makeSkinClass(NativeClass, useNativeConstructor): Function;
};

Utilities and Helpers

Types

// Core wrapper classes
class SkinDb extends Db {
  collection(name, options): SkinCollection;
  bind(name, options): SkinCollection;
  admin(): SkinAdmin;
  gridStore(...args): SkinGridStore;
  open(callback): SkinDb;
  close(callback): SkinDb;
  isOpen(): boolean;
}

class SkinCollection extends Collection {
  bind(extendObject): void;
  findItems(query, options, callback): SkinCollection;
  findEach(query, options, eachCallback): SkinCollection;
  findById(id, callback): SkinCollection;
  updateById(id, doc, callback): SkinCollection;
  removeById(id, callback): SkinCollection;
}

class SkinCursor extends Cursor {
  // All standard cursor methods plus lazy connection handling
}

class SkinAdmin extends Admin {
  // All standard admin methods with enhanced connection handling
}

class SkinGridStore extends GridStore {
  // All standard GridStore methods with lazy connection
}

// Connection states
const STATE_CLOSE = 0;
const STATE_OPENNING = 1; 
const STATE_OPEN = 2;

// Default port constant
const DEFAULT_PORT = 27017;

// MongoDB native types (re-exported)
class ObjectID {
  constructor(id): ObjectID;
  toString(): string;
  static createFromHexString(hex): ObjectID;
  static isValid(id): boolean;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/mongoskin@2.1.x
Publish Source
CLI
Badge
tessl/npm-mongoskin badge