包详细信息

mongoskin

kissjs12.2kMIT2.1.0

The future layer above node-mongodb-native

mongodb, database, nosql

自述文件

Gitter

mongoskin

Build Status Dependencies Coverage Status NPM version

NPM

NPM

Install

$ npm install mongoskin

Usage

Use dburl

var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/integration_tests", {native_parser:true});
db.bind('article');
db.article.find().toArray(function(err, items) {
        db.close();
});

Use ReplSet

var mongo = require('mongoskin');
var Server = mongo.Server;
var Db = mongo.Db;

var replSet = new ReplSetServers([
        new Server('localhost', 30000),
        new Server('localhost', 30001),
        new Server('localhost', 30002),
]);

var db = new Db('integration_test_', replSet, {w:0, native_parser: (process.env['TEST_NATIVE'] != null)});
// no need open and on('fullsetup', ...)
db.collection('myconnection').find().setReadPreference(ReadPreference.SECONDARY).toArray(function(err, items) {
        db.close();
});

Model helper:

var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/integration_tests", {native_parser:true});
db.bind('article').bind({
    getByAuthor: function(author_id, callback) {
        this.findOne({author_id: author_id}, callback);
    }
});
db.article.getByAuthor(author_id, function(err, article) {
        console.log(article);
});

Origin API part

For detail API reference see node mongodb API. Mongoskin is just change the API call chain.

We make some common use functions in promise mode, we call it SkinClass of a normal Class. And the API is almost same with official API.

module

origin:

var mongo = require('mongodb');
var Db = mongo.Db;
var Server = mongo.Server;
var MongoClient = mongo.MongoClient;
var ReplSetServers = mongo.ReplSetServers;
...

mongoskin:

var mongo = require('mongoskin');
var Db = mongo.Db;
var Server = mongo.Server;
var MongoClient = mongo.MongoClient;
var ReplSetServers = mongo.ReplSetServers;
...

MongoClient.connect(...)

returns a Db instance

alias origin MongoClient.connect(..., function(err, db) { .... })

origin:

MongoClient.connect(..., function(err, db) {
})

mongoskin:

var db = MongoClient.connect(...)

db.collection(..., [callback])

returns a Collection instance

alias origin db.collection(..., function(err, collection) {....})

origin:

var db = new Db(...);
db.open(function(err, db) {
    db.collection('myCollection', {strict: true}, function(err, myCollection) {
        // myCollection.find() ...
    });
});

mongoskin:

var db = new Db(...);
var myCollection = db.collection('myCollection', {strict: true});

MongoSkin API part

module.db(...)

alias MongoClient.connect(...)

module.helper.toObjectID(hexStr)

convert String to ObjectID instance.

db.bind(name, options)

alias db[name] = db.collection(name, options)

db.bind('article')
db.article.find().toArray(function(err, items) {
  assert.ok(err == null);
});

db.admin(...)

alias new Admin(db, ...)

db.grid(...)

alias new Grid(db, ...)

db.gridStore(...)

alias new GridStore(db, ...)

collection.bind(extendObject)

each method of extendObject will be bind to collection.

collection.findById(id, ...)

alias collection.find({_id: toObjectID(id)}, ...)

collection.updateById(id, ...)

alias collection.update({_id: toObjectID(id)}, ...)

collection.removeById(id, ...)

alias collection.remove({_id: toObjectID(id)}, ...)

NOTE!! mongoskin API change from 1.3.20

Since node-mongodb-native has change a lot of API, mongoskin redesign from 1.3.20. The version number keep same with node-mongodb-native. And the API appearence is also keep same with node-mongodb-native

Removed API from mongoskin 1.3.20

  • module.bind
  • module.Skin*
  • module.router
  • skinDb.toId
  • skinDb.toObjectId
  • skinDb.gridfs
  • skinCollection.bind

Modified API from mongoskin 1.3.20

  • module.db
  • skinDb.bind

Additional API from mongoskin 1.3.20

  • module.MongoClient
  • module.Grid
  • module.GridStore
  • module.helper.toObjectID

Authors

Below is the output from git-summary.

 project  : node-mongoskin
 repo age : 2 years, 10 months
 active   : 84 days
 commits  : 180
 files    : 44
 authors  :
    49    Lin Gui                 27.2%
    44    fengmk2                 24.4%
    34    guilin 桂林           18.9%
    23    Gui Lin                 12.8%
     5    guilin                  2.8%
     2    Raghu Katti             1.1%
     2    Merlyn Albery-Speyer    1.1%
     2    Paul Gebheim            1.1%
     2    Joakim B                1.1%
     2    François de Metz       1.1%
     1    Wout Mertens            0.6%
     1    Yuriy Nemtsov           0.6%
     1    fresheneesz             0.6%
     1    humanchimp              0.6%
     1    Alan Shaw               0.6%
     1    wmertens                0.6%
     1    Aneil Mallavarapu       0.6%
     1    Gustav                  0.6%
     1    Harvey McQueen          0.6%
     1    Joe Faber               0.6%
     1    Matt Perpick            0.6%
     1    Philmod                 0.6%
     1    Quang Van               0.6%
     1    Rakshit Menpara         0.6%
     1    Shawn Jonnet            0.6%

License

(The MIT License)

Copyright (c) 2011 - 2012 kissjs.org

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.

更新日志

2.0.1 / 2015-10-09

  • Return full admin class rather than just admin collection when calling .admin() #177

2.0.0 / 2015-09-21

  • Support for mongodb driver v2.x
  • The Grid class was removed in mongodb driver 2.0 and so mongoskin.Grid is gone as well.
  • utils.makeSkinClass()'s optional third parameter isSingle is removed.
  • db.collection() no longer accepts a callback. Use var collection = db.collection('collname'); instead.

0.6.1 / 2013-11-24

  • Merge pull request #122 from Philmod/older-mongodb
  • older version of mongodb
  • Merge pull request #108 from fresheneesz/patch-1
  • Merge pull request #114 from nemtsov/patch-1
  • fix typo: this.hit -> this.hint
  • Vastly improving the documentation around the mongoskin.db method

0.6.0 / 2013-07-16

  • changed version in package.json to 1.3.x for mongodb
  • Upgraded the mongo db version to 1.3.x. Mixing mongodb 1.2.x which mongoskin 0.5.0 depends on and latest mongodb 1.3.x causes Mongodb connection timeout problems in replication environment.
  • Use HTTPS so GitHub doesn't cache dependency badge
  • add Dependencies status image
  • Corrected repository URL in package.json
  • Documentation improvements
  • add 0.9 version test

0.5.0 / 2012-12-29

  • fixed unsafe mode warnning log
  • Merge pull request #84 from kingpearl/master
  • MongoDB 1.2.x support
  • Merge pull request #73 from jockster/master
  • Merge pull request #75 from voke/patch-1
  • Fix typo
  • fixed bind() test cases;
  • Minor error in readme. Now updated
  • Updated readme according to issue #72

0.3.4 / 2011-03-24

  • fix global leaks

0.3.3 / 2011-03-15

  • Add rootCollection option to SkinGridStore.exist

0.3.2 / 2011-03-01

  • exports all classes of node-mongodb-native

0.3.1 / 2011-02-26

  • bug fix #33

0.3.0 / 2011-01-19

  • add ReplSet support
  • bug fix

0.2.3 / 2011-01-03

  • add db.toObjectID
  • fix #25 for node-mongodb-native update

0.2.2 / 2011-12-02

  • add bind support for embeded collections, e.g. db.bind('system.js')
  • add method toId to SkinDB
  • add property ObjectID, bson_serializer to SkinDB.
  • SkinCollection.prototype.id is now deprecated.

0.2.1 / 2011-11-18

  • add ObjectId support for XXXXById

0.2.0 / 2011-11-06

  • add SkinDB.gridfs

0.1.3 / 2011-05-24

  • add SkinCollection.removeById

0.1.2 / 2011-04-30

  • add mongoskin.router