Code Monkey home page Code Monkey logo

node-mongoskin's People

Contributors

alanshaw avatar albert-iv avatar coen-hyde avatar deltasquare4 avatar fengmk2 avatar francois2metz avatar fresheneesz avatar gitter-badger avatar guileen avatar hmcqueen avatar humanchimp avatar nemtsov avatar perfaram avatar peterdavehello avatar ratson avatar rkatti avatar rschmukler avatar sjonnet avatar vkarpov15 avatar voke avatar wmertens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-mongoskin's Issues

broken connection

Hello, I have strange issue, which I can't track:

TypeError: Property '-1' of object  is not a function
    at EventEmitter.<anonymous> (~/node_modules/mongoskin/lib/mongoskin/db.js:219:36)
    at EventEmitter.emit (events.js:88:20)
    at ~/node_modules/mongoskin/lib/mongoskin/db.js:98:20
    at ~/node_modules/mongoskin/lib/mongoskin/db.js:111:9
    at ~/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:158:16
    at [object Object].<anonymous> (~/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:311:7)
    at [object Object].emit (events.js:67:17)
    at [object Object].<anonymous> (~/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:99:15)
    at [object Object].emit (events.js:70:17)
    at Socket.<anonymous> (~/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:403:10)

mongoskin version: 0.2.2
node : 0.6.6
mongo: 2.0.1

Mac OS X 10.6.8

Loss of Binding inside Callback

When making a call to the database like so:

console.log(this);
db.collection('users').find(data, {limit:1}).toArray(function(err, result){
    console.log(this);
});   

The console.log inside the callback is in a different scope. This makes it very tough to do things like.

db.collection('users').find(data, {limit:1}).toArray(function(err, result){
   if(err) throw new noData('Bad Stuff'); 
});   

how to use native BSON?

I'd like to know how to use native BSON with package.json and I think it would be a good thing to put in the docs.

I think if I just listed mongodb and mongoskin as my dependencies in package.json, it would install mongodb twice and mongoskin would use its mongodb. Correct?

options.database ignored when creating skinServer without ReplSet

I believe line 104 in index.js should be more like database = options.database || config.database; to make it easier to have a standard way to create skinServer instances based on whether you're going to a single DB or to a Replica Set.

I'm not quite clear on why options.database would be ignored in this use case, forcing one to pass the database name as part of the URL. Is there a specific reason?

Argument passed in must be a single String of 12 bytes or a string of 24 hex characters

db.connection.findById('123', function () {})
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
    at Function.createFromHexString (/Users/mk2/git/todo/node_modules/mongoskin/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js:209:11)
    at [object Object].<anonymous> (/Users/mk2/git/todo/node_modules/mongoskin/lib/mongoskin/db.js:37:24)
    at [object Object].findById (/Users/mk2/git/todo/node_modules/mongoskin/lib/mongoskin/collection.js:194:31)
    at /Users/mk2/git/todo/controllers/todo.js:45:11
    at Object.lookup [as handle] (/Users/mk2/git/todo/node_modules/urlrouter/lib/urlrouter.js:71:18)
    at next (/Users/mk2/git/todo/node_modules/connect/lib/proto.js:190:15)
    at Object.handle (/Users/mk2/git/todo/node_modules/connect-render/lib/render.js:173:5)
    at next (/Users/mk2/git/todo/node_modules/connect/lib/proto.js:190:15)
    at Object.handle (/Users/mk2/git/todo/node_modules/connect/lib/middleware/csrf.js:48:88)
    at next (/Users/mk2/git/todo/node_modules/connect/lib/proto.js:190:15)

Undefined var outside find

Hello,
Why when I associate items to this array return in console UNDEFINED ??

    db.users.findSchedule(time, function(err, items){
        this.lista = items;
    });
console.log(this.lista);

The same thing with this other code:

    var lista = [];
    
    db.users.findSchedule(time, function(err, items){
        lista = items;
    });
    console.log(lista);

any help is very appreciated!

-A

caching

May I request that you add a caching option to it?

I'm not sure of mongodb does this, but if not it would probably boost
perfomrance.

For example, if a collection('test'.).find({name:'Bobo'}) is called
the , the , and the would be saved.
The next time collection('test'.).find({name:'Bobo'}) is called it
would use the saved data unless there was a update/delete/insert used
on the collection.
(Perhaps there should be a size limit on cacheable collections)

It would be usefull, if there's only one node that connects to the db
(which is often the case).

If I remember correctly the nodejs couchdb module can do caching

middleware

When to middleware?

all these points are related with web development.

  1. mongodb finding generally need to retrieve related documents, and the retrieval method for every find generally same.
  2. we need more than one querying or updating within one HTTP request. if any query or update return err, we should stop next query and handle the error and response 500 page. the middleware should know response instance.
  3. as finding need to retrieve related document, the updating also need to filter retrieved document. Sometimes, we need to convert field types. But this can be done before operation.

So we need a middleware, middleware could be function(fn) returns function(err, replies). We can also define a special middleware to handle relative retrieval fields, and findItems, findEach, findByid can use it automatically, and find for raw query.

E11000 is not being forwarded to the callback of Collection#insert

Hi there —

I'm having a problem because the E11000 error for a non-unique value is not being forwarded to my callback. Consider the following code for the latest mongoskin (0.2.1)

var db, mongo;

mongo = require('mongoskin');

db = mongo.db('localhost:27017/test');

db.collection('unique_index_fails').ensureIndex({qux: 1}, {unique: true}, function() {
  var docs;

  docs = [{qux: 'same'}, {qux: 'different'}, {qux: 'same'}]; // Oops, two qux have the same value

  db.collection('unique_index_fails').insert(docs, function(err) {
    console.log('err should be 11000', err); // err is null

    db.collection('unique_index_fails').find(function(err, results) {
      results.toArray(console.log);  // only have one document with {qux:'same'}
    });
  });
});

Console output:

err should be 11000 null
null [ { qux: 'same', _id: 4ed42f9b6b159afb75000001 },
  { qux: 'different', _id: 4ed42f9b6b159afb75000002 } ]

I tested with mongoskin 0.2.1 and mongodb 2.0.1

Do I need to call db.open and collection.open?

I want to know if it's required to call db.open and colleciton.open?

In some of your examples you don't use the open methods, so will it still connect automatically if it's left out?

MongoDB 0.9.7 update breaks mongoskin

Updating to 0.9.7 MongoDB throws an error during the connection saying that the host and port must be specified. Rolling MongoDB back to 0.9.6-23 resolves the issue but this looks like it will be a problem going forward.

findById 需要兼容ObjectID

db.users.findById(uid) uid如果是url传递进来会是string,又可以通过post.author_id等其他方式直接获得objectid, 希望findById的id参数能支持这两种类型。

TypeError: Cannot call method 'open' of null

模拟网络不通的时候,捕获到一下错误:

/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/db.js:99
      this.db.open(function (err, db) {
              ^
TypeError: Cannot call method 'open' of null
    at [object Object].open (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/db.js:99:15)
    at [object Object].open (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/collection.js:111:19)
    at [object Object]._find (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/utils.js:64:10)
    at [object Object].find (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/collection.js:292:16)
    at [object Object].findItems (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/collection.js:191:13)
    at Object.getAll (/Users/mk2/svn/xx/proxy/field.js:100:13)
    at syncFields (/Users/mk2/svn/xx/proxy/field.js:119:11)
    at /Users/mk2/svn/xx/proxy/field.js:158:14
    at Object.error (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/utils.js:27:5)
    at EventEmitter.<anonymous> (/Users/mk2/svn/xx/node_modules/mongoskin/lib/mongoskin/utils.js:66:17)

TypeError: undefined is not a function

TypeError: undefined is not a function
    at /mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:1349:11
    at [object Object].close (/mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/repl_set_servers.js:965:9)
    at /mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:1347:28
    at /mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/repl_set_servers.js:760:11
    at [object Object].<anonymous> (/mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:390:7)
    at [object Object].emit (events.js:88:20)
    at [object Object].<anonymous> (/mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:96:15)
    at [object Object].emit (events.js:70:17)
    at Socket.<anonymous> (/mk2/weibo/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:388:10)
    at Socket.emit (events.js:67:17)

event emitter leak warning

When running many queries directly after the other there are many event listeners added to the database open event.

This means you get a warning

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at EventEmitter. (events.js:139:15)
at EventEmitter.once (events.js:160:8)
at [object Object].open (/home/raynos/Documents/mongo-col/node_modules/mongoskin/lib/mongoskin/db.js:54:25)
at [object Object].dropCollection (/home/raynos/Documents/mongo-col/node_modules/mongoskin/lib/mongoskin/db.js:186:17)
at [object Object].drop (/home/raynos/Documents/mongo-col/node_modules/mongoskin/lib/mongoskin/collection.js:130:15)
at mongoSkinBench (/home/raynos/Documents/mongo-col/benchmarks/benchmarks.js:98:14)
at runNTimes (/home/raynos/Documents/mongo-col/benchmarks/benchmarks.js:115:9)
at /home/raynos/Documents/mongo-col/benchmarks/benchmarks.js:43:17
at /home/raynos/Documents/mongo-col/benchmarks/benchmarks.js:121:28
at /home/raynos/Documents/mongo-col/benchmarks/benchmarks.js:89:17

Run my benchmarks to reproduce this

integration tests fail

using the latest version installed with npm, running integraton/integration_tests.js yields:

======== test MongoSkin.db ========
======== test MongoSkin.router ========
======== test MongoSkin.bind ========
======== test SkinDb bson ========
======== test SkinDb.bind ========
======== test SkinDb.open ========
======== test normal method of SkinDb ========
======== test SkinDb.collection ========
======== test SkinCollection.open ========
======== test normal method of SkinCollection ========
======== test SkinCollection.drop ========
======== test SkinCollection.find ========
======== test SkinCursor ========
======== deep future test ========
======== test SkinCollection.findById ========
======== test SkinCollection.removeById ========

assert.js:81
  throw new assert.AssertionError({
        ^
AssertionError: true ==
    at /cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongoskin/integration/integration_tests.js:148:20
    at Collection.remove (/cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongodb/lib/mongodb/collection.js:189:12)
    at /cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongoskin/lib/mongoskin/collection.js:62:16
    at [object Object].open (/cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongoskin/lib/mongoskin/collection.js:78:14)
    at [object Object].remove (/cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongoskin/lib/mongoskin/collection.js:58:17)
    at [object Object].removeById (/cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongoskin/lib/mongoskin/collection.js:165:15)
    at /cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongoskin/integration/integration_tests.js:147:20
    at [object Object]. (/cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongodb/lib/mongodb/collection.js:687:5)
    at [object Object].emit (events.js:67:17)
    at [object Object]. (/cygdrive/c/Users/vincent/Documents/devel/test/node_modules/mongodb/lib/mongodb/connections/server.js:88:12)

possible EventEmitter memory leak detected

I'm using collection.findOne and collection.find with anonymous functions as callbacks. Each time a client requests a thing I'm calling those. If more then 10 requests are fired/listening I get the following Error:


(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at EventEmitter. (events.js:139:15)
at [object Object].open (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:98:27)
at [object Object].findOne (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:70:10)
at [object Object].getVariable (/projects/xplane/X-Plane-Flight-Planner/lib/apt_nav_data.js:155:16)
at /projects/xplane/X-Plane-Flight-Planner/routes/index.js:41:18
at Array.1 (/projects/xplane/X-Plane-Flight-Planner/lib/apt_nav_data.js:159:16)
at EventEmitter. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:72:29)
at EventEmitter.emit (events.js:88:20)
at EventEmitter. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:107:33)
at EventEmitter.emit (events.js:88:20)
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace:
at EventEmitter. (events.js:139:15)
at [object Object].open (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/db.js:54:25)
at [object Object].open (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:104:19)
at [object Object].findOne (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:70:10)
at [object Object].getVariable (/projects/xplane/X-Plane-Flight-Planner/lib/apt_nav_data.js:155:16)
at /projects/xplane/X-Plane-Flight-Planner/routes/index.js:40:16
at Array.1 (/projects/xplane/X-Plane-Flight-Planner/lib/apt_nav_data.js:159:16)
at EventEmitter. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:72:29)
at EventEmitter.emit (events.js:88:20)
at EventEmitter. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongoskin/lib/mongoskin/collection.js:107:33)

You can see my code here: https://github.com/der-On/X-Plane-Flight-Planner

Explain triggers index full scan

Hi,

When I use explain with mongoskin, mongodb makes a full scan but doesn’t say it !

here is the strange way :
first, I try a find in mongodb shell : I got only 10 records and a few records scanned.
Next I try the same in node JavaScript : 3 tests, same results (I don’t find how to combine the each way and the limit function)
MongoDB makes a full scan but doesn’t say it !
I test also a sort to verify.

or I make a mistake ???
can you explain ???

thank you
Denis

First :
Here is the reference in MongoDB JavaScript shell :

db.art2.find({pays:'FR',_keywords:{$all:[/^red/]},org_info:{$elemMatch:{org_id:2521,cadre:{$gt:0}}}},{_id:0,_keywords:0,org_info:0}).limit(10).explain()

Wed Jul 11 22:46:21 [conn9] query mdb.art2 query: { query: { pays: "FR", _keywords: { $all: [ /^red/ ] }, org_info: { $elemMatch: { org_id: 2521.0, cadre: { $gt: 0.0 } } } }, $explain: true } ntoreturn:10 nscanned:2455 nreturned:1 reslen:521 110ms

I got only 10 records and a few records scanned.

Next : The same in node JavaScript : 3 tests, same results. MongoDB makes a full scan.

// toArray and limit()
db.collection('art2')
.find({'pays':'FR','_keywords':{$all:[/^red/]},'org_info':{$elemMatch:{'org_id':2521,'cadre':{$gt:0}}}},{'_id':false,'pays':false}
,{explain:1}
).toArray(function(err, rArt) {
r.write(JSON.stringify(rArt, null, ' '));
r.end();
}).limit(10);

Wed Jul 11 22:35:06 [conn27] query mdb.art2 query: { query: { pays: "FR", _keywords: { $all: [ /^red/ ] }, org_info: { $elemMatch: { org_id: 2521, cadre: { $gt: 0 } } } }, $explain: true } ntoreturn:10 nscanned:41058 nreturned:1 reslen:521 914ms

// toArray and limit:
db.collection('art2')
.find({'pays':'FR','_keywords':{$all:[/^red/]},'org_info':{$elemMatch:{'org_id':2521,'cadre':{$gt:0}}}},{'_id':false,'pays':false}
,{explain:1,limit:10}
).toArray(function(err, rArt) {
r.write(JSON.stringify(rArt, null, ' '));
r.end();
});

Wed Jul 11 22:36:27 [conn28] query mdb.art2 query: { query: { pays: "FR", _keywords: { $all: [ /^red/ ] }, org_info: { $elemMatch: { org_id: 2521, cadre: { $gt: 0 } } } }, $explain: true } ntoreturn:10 nscanned:41058 nreturned:1 reslen:521 877ms

// each way and limit:
db.collection('art2')
.find({'pays':'FR','_keywords':{$all:[/^red/]},'org_info':{$elemMatch:{'org_id':2521,'cadre':{$gt:0}}}},{'_id':false,'pays':false}
,{explain:1,limit:10}
,function(err, rArts) {
if (rArts) {
rArts.each(function(err, rArt) {
if (rArt) {
r.write(JSON.stringify(rArt, null, ' '));
}
else r.end();
});
}
else r.end();
});

Wed Jul 11 22:38:24 [conn29] query mdb.art2 query: { query: { pays: "FR", _keywords: { $all: [ /^red/ ] }, org_info: { $elemMatch: { org_id: 2521, cadre: { $gt: 0 } } } }, $explain: true } ntoreturn:10 nscanned:41058 nreturned:1 reslen:521 878ms

The result will be the same if I add a sort. In the shell we can notice the full scan :

db.art2.find({pays:'FR',_keywords:{$all:[/^red/]},org_info:{$elemMatch:{org_id:2521,cadre:{$gt:0}}}},{_id:0,_keywords:0,org_info:0}).sort({article_id:1}).limit(10).explain()

Wed Jul 11 23:08:37 [conn9] query mdb.art2 query: { query: { pays: "FR", _keywords: { $all: [ /^red/ ] }, org_info: { $elemMatch: { org_id: 2521.0, cadre: { $gt: 0.0 } } } }, orderby: { article_id: 1.0 }, $explain: true } ntoreturn:10 nscanned:41058 scanAndOrder:1 nreturned:1 reslen:422 1027ms

Cannot read property 'ObjectID' of undefined

node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'ObjectID' of undefined
at new (/Users/nickliu/git/nodeblog/node_modules/mongoskin/lib/mongoskin/db.js:61:37)
at MongoSkin.db (/Users/nickliu/git/nodeblog/node_modules/mongoskin/lib/mongoskin/index.js:86:12)

findOne() without callback

  • Steps to reproduce: Use findOne() without callback, e. g. db.myEmptyCollection.findOne()
  • Expected result: findOne() returns the result, or null if no match found, just like in the mongo shell
  • Actual result: findOne() throws an exception that must be caught

This should be possible:


Error: CALL_NON_FUNCTION

I'm not sure if this is really a mongoskin issue or not, however it's what my log file spits out after the application kept running several hours without any error-


node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: object is not a function
at CALL_NON_FUNCTION (native)
at [object Object]. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongodb/lib/mongodb/connection/server.js:211:28)
at [object Object].g (events.js:156:14)
at [object Object].emit (events.js:70:17)
at /projects/xplane/X-Plane-Flight-Planner/node_modules/mongodb/lib/mongodb/connection/server.js:495:35
at [object Object]. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongodb/lib/mongodb/connection/server.js:442:7)
at [object Object].emit (events.js:88:20)
at [object Object]. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:112:15)
at [object Object].emit (events.js:70:17)
at Socket. (/projects/xplane/X-Plane-Flight-Planner/node_modules/mongodb/lib/mongodb/connection/connection.js:404:12)

mvc helper

对于MVC helper的实现,只是针对collection的,能否加下对toArray()后的对象的mvc helper的支持。
例如:

db.bindItem('posts', {
    getUrl: function(){ ... }
});
db.posts.find().toArray(function(err, posts){
    posts[0].getUrl()
});

Schema Validation

Hello,
Is there a way to validate the content before save like mongoose ?

Thanks
Alex

NPM INSTALL FAIL IN WIN7

E:\Workspace\Code\PureReader>npm install mongoskin
npm http GET https://registry.npmjs.org/mongoskin
npm http 200 https://registry.npmjs.org/mongoskin
npm http GET https://registry.npmjs.org/mongoskin/-/mongoskin-0.3.3.tgz
npm http 200 https://registry.npmjs.org/mongoskin/-/mongoskin-0.3.3.tgz
npm http GET https://registry.npmjs.org/mongodb
npm http 200 https://registry.npmjs.org/mongodb
npm http GET https://registry.npmjs.org/mongodb/-/mongodb-0.9.9-7.tgz
npm http 200 https://registry.npmjs.org/mongodb/-/mongodb-0.9.9-7.tgz
npm ERR! Unsupported
npm ERR! Not compatible with your operating system or architecture: [email protected].
9-7
npm ERR! Valid OS: linux,darwin,freebsd,sunos,windows
npm ERR! Valid Arch: any
npm ERR! Actual OS: win32
npm ERR! Actual Arch: ia32
npm ERR!
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "D:\Tool\nodejs\node.exe" "D:\Tool\nodejs\node_modules
\npm\bin\npm-cli.js" "install" "mongoskin"
npm ERR! cwd E:\Workspace\Code\PureReader
npm ERR! node -v v0.6.13
npm ERR! npm -v 1.1.9
npm ERR! code EBADPLATFORM
npm ERR! message Unsupported
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! E:\Workspace\Code\PureReader\npm-debug.log
npm not ok

Global Variables

Including mongoskin into mocha causes mocha to flag global variable leaks

     Error: global leaks detected: mongoskin, skindb, i, len

These vars seems to come from lib/mongoskin/index.js, is this intended behavior?

Error: db object already connecting, open cannot be called multiple times

I met a error in the latest 0.3.6

  throw new Error("db object already connecting, open cannot be called multi
          ^
Error: db object already connecting, open cannot be called multiple times
    at Db.open (/home/ubuntu/sites/admin/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:234:11)
    at [object Object].open (/home/ubuntu/sites/admin/node_modules/mongoskin/lib/mongoskin/db.js:74:13)
    at [object Object].open (/home/ubuntu/sites/admin/node_modules/mongoskin/lib/mongoskin/collection.js:104:19)
    at [object Object].findOne (/home/ubuntu/sites/admin/node_modules/mongoskin/lib/mongoskin/collection.js:70:10)

my code works in the 0.3.5 with old mongodb

When to close?

I have learned that I should not create a new connection for each request of my web app, but have one connection for the complete lifetime of the app.

How do I close the connection properly when the user shuts down the program (e.g. by hitting Ctrl+C)?
Do I NEED to do this?
What happens if a connection does not get closed explicitly?

Reusing mongodb-native db object

I would like to reuse a single db connection across multiple SkinDb objects. I can sort of make this work by manually changing the SkinDb's state.

var base = new mongo.Db(...);
base.open(function(err) {
    ...
    var db = new mongoskin.SkinDb(base);
    db.state = 2;
});

It would be nice if the SkinDb listened for changes to state in the native Db object and updated its state accordingly. Is this something that you'd consider including in Mongoskin? I can put together a pull request if so.

When / why to use auto_reconnect?

When respectively why should I use auto_reconnect?

I understand that it re-connects when the connection gets closed.
But when could that happen, if I do not close it explicitly?

To put it in other words: What is the recommended best-practice?

repeated connect failures result in listener proliferation and multiple callbacks

The "open" listeners for collection, cursor, and db are all registered using EventEmitter.addListener instead of EventEmitter.once. If the first open attempt errors out, the listener callback is properly called with the error, but the callback remains registered. A second attempt will add another listener, but if that errors out as well, both the new AND the original callbacks will be invoked.

Here's a program that demonstrates the issue:

var mongo = require('mongoskin');
var db = mongo.db('localhost:27017/bogus');
var coll = db.collection('does_not_matter');

var doQuery = function () {
  console.error();
  console.error('in doQuery');
  coll.find( {}, function( error, results ) { 
    if (error) {
      console.error('got an error:',error);
      return;
    }   
    console.error(results);
  }); 
};

setInterval( doQuery, 1000 );

Since this is calling a collection method, the problem is exacerbated by the fact that both the collection and the underlying db have callbacks. So the first error invokes the callback method once, the second error invokes it four times, the third nine, and so on.

I think the solution to this is to use EventEmitter.once instead of EventEmitter.addListener. This will remove the callback once its fired. I'm creating a pull request with that modification.

collection.group不能分组统计问题?

    var key = {task_id:true};
    var where = {task_id: {$in: ids}};     //ids 是保护两个不同id的数组
collection.group(
        key,
    where,
    {count: 0},
    function(obj, prev) {prev.count++;prev.task_id=obj.task_id;}
        , function(err, retCount) {  //retCount只返回一条记录,应该是返回两行才对吧?或者是我接口调用有误?

});

Better examples needed

Hi there,

Great work on the module, except you seriously need some better examples.

For example, doing an update by Id.

You have: updateById(_id, ..., callback)

Unfortunately, I am not a mind reader, so .... doesn't mean a row of beans to me.

It would be awesome if you could take some time to make your examples more verbose to the average noob.

Here's the issue I'm coming against:

In the cli I can do:

db.sessions.update( {'_id': ObjectId('4eb5444d39e153e60b000001')}, {$set: {"status":'unavailable'}} );

In node I am trying to do:

store.collection('sessions').update( {'_id': '4eb5444d39e153e60b000001'}, {$set: {"status":'unavailable'}} );

But I keep on getting "Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters in hex format"

I am now totally stuck. If you had better examples explaining things, I'm sure I wouldn't be here hours later still with no resolution!

Thanks!

How to use Aggregation Framework in mongoskin?

http://www.mongodb.org/display/DOCS/Aggregation+Framework

If I want to run this command, how can I do it?

> db.runCommand({aggregate: "posts", pipeline: [
{
   // extract the fields we'll need
   $project: {
        title : 1,
        url : 1,
        comments : 1
    }
},
{
    // explode "comments" array into separate documents
    $unwind: "$comments"
},
{
    // count up votes by author
    $group : {
        _id : "$comments.author",
        popularity : {$sum : "$comments.votes"}
    }
},
{
    // sort by the new popular field
    $sort: {
        "popularity" : -1
    }
}]})

createCollection throws cannot call method 'getRequestId' of null

I'm testing mongoskin to move away from mongoose and I'm running this example from the docs:

db.createCollection("test", function(err, collection){
//console.log(collection.insert);
collection.insert({"test":"value"});
});

it's giving me:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot call method 'getRequestId' of null
at [object Object].executeCommand (/Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:757:48)
at Collection.insertAll (/Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/collection.js:312:26)
at Collection.insert (/Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/collection.js:110:8)
at /Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/test.js:22:16
at /Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:402:14
at /Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:156:7
at /Users/camilo/Dropbox/Development/buglabs/playground/mongoskin/node_modules/mongoskin/no

any ideas?

TypeError: Cannot call method 'open' of null

/home/mk2/node_modules/mongoskin/lib/mongoskin/db.js:99
      this.db.open(function (err, db) {
              ^
TypeError: Cannot call method 'open' of null
    at SkinDb.open (/home/mk2/node_modules/mongoskin/lib/mongoskin/db.js:99:15)
    at SkinCollection.open (/home/mk2/node_modules/mongoskin/lib/mongoskin/collection.js:111:19)
    at exports.bindSkin.obj.(anonymous function) [as _find] (/home/mk2/node_modules/mongoskin/lib/mongoskin/utils.js:64:10)
    at SkinCollection.find (/home/mk2/node_modules/mongoskin/lib/mongoskin/collection.js:292:16)
    at SkinCollection.findItems (/home/mk2/node_modules/mongoskin/lib/mongoskin/collection.js:191:13)
    at Object.exports.getAll (/home/mk2/proxy/field.js:120:13)
    at syncFields (/home/mk2/proxy/field.js:139:11)
    at exports.validateFields (/home/mk2/proxy/field.js:188:14)
    at Object.exports.error (/home/mk2/node_modules/mongoskin/lib/mongoskin/utils.js:27:5)
    at EventEmitter.exports.bindSkin.obj.(anonymous function) (/home/mk2/node_modules/mongoskin/lib/mongoskin/utils.js:66:17)

support replica sets

It would be great if mongoskin could support replica sets

node-mongodb-native supports replica sets through the "ReplSetServers" class.

Cannot read property '_serverState' of undefined

Bug occured for MongoSkin 0.3.5 + node-mongodb-native 1.0.1. A new version of the MongoDB driver crashes your latest version because you use >= in the package dependencies.

TypeError: Cannot read property '_serverState' of undefined
   at Db.state (~/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:1810:31)
   at Object.<anonymous> (~/node_modules/mongoskin/lib/mongoskin/db.js:199:28)
   at Module._compile (module.js:441:26)
   at Object..js (module.js:459:10)
   at Module.load (module.js:348:31)
   at Function._load (module.js:308:12)
   at Module.require (module.js:354:17)
   at require (module.js:370:17)

search by function ?

Hello,
in the terminal mongo this works:

var f = function(){return (this.root.address.test('testRegex') && this.root.name === 'MyName')};
db.my.find(f);

I can not do it on node.js:
var f = function(){return (this.root.address.test('testRegex') && this.root.name === 'MyName')};
db.my.find(f).toArray(feedback); //Cannot call method 'toArray' of undefined

but :
db.my.find().toArray(feedback); // work

an idea?
thank you !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.