marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
350 stars 50 forks source link

collection.find() not firing/returning empty array on server #86

Closed ChristopherBiscardi closed 12 years ago

ChristopherBiscardi commented 12 years ago
var Mongolian = require('mongolian');
var ObjectId =  require('mongolian').ObjectId;
var db = new Mongolian();  //db server information removed
var matches= db.collection('matches');
var user = '4f247fce78b1b3f47f00000a';

matches.find({uids:new ObjectId(user)})
  .sort({score:1})
  .limit(100)
  .toArray(function (err, matchArr) {
    console.log(matchArr);
  });

This code works on my local computer. I can successfully connect to a remote database server and return an array of matches. When I upload the same exact code to the app server, The connection to the database server is successful, however, the .find() doesn't fire. In another case the the same find function returns an empty array on the server (The find() function works fine when running on my local computer with a remote database).

Am I missing something obvious here?

marcello3d commented 12 years ago

Everything you have here looks ok. It's possible something is timing out or not connecting properly (how are you determining that?). This is a good candidate for GH-85.

ChristopherBiscardi commented 12 years ago

I'm currently checking the mongod log output as the script is run. Connection seems to be established, query never hits the database.

Agreed, I'll play around with #85 tomorrow.

ChristopherBiscardi commented 12 years ago

I've found some interesting code.

It seems to run through the library until it hits this line of code. I can find an _authorizeQueue variable in one other function but It sets the var to [] at the beginning of the function.

this._authorizeQueue.push([command,callback])

and a contrived stack trace on the line above the above function:

Error
at [object Object].sendCommand (/Users/chris/Desktop/test/db_test/node-mongolian/lib/db.js:87:21)
at [object Object].nextBatch (/Users/chris/Desktop/test/db_test/node-mongolian/lib/cursor.js:140:17)
at [object Object].toArray (/Users/chris/Desktop/test/db_test/node-mongolian/lib/cursor.js:215:14)

It would seem that the command never gets sent and instead ends it's life in an array that never gets used at db.js:87

Commit 767d7b8a70e01b966256e8ee0f6c7742061833e5 is where this code was introduced

I plugged in this code just underneath the _authorizeQueue

        this.server.sendCommand(command,callback); //calling send in server.js:247

and this error pops up:

 [warn] Authentication failed for `username-redacted` @ Mongolian
ChristopherBiscardi commented 12 years ago

Fixed the issue.

Ends up mongod was running without --auth and we were trying to authenticate against it with a username and pw that were in the users collection.

Running mongod --auth fixed the issue.