Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ChristopherBiscardi opened this issue Jan 29, 2012 · 4 comments
Closed

Comments

@ChristopherBiscardi
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

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 767d7b8 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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants