2

i have a problem with a query from NodeJS to MongoDb (i'm using native client).

Basically, i got 2 different results when performing the query from mongo console and from node app. (with native mongo client : i'm not using mongoose or other modules )

this is my query object (im using collection.find() ):

{ 'stats.campaign_id': 6010108824797,
  'stats.collectDate': { '$gte': 1375628400, '$lt': 1375632000 } }

Basically, the response from the Node app seems to be relative to only the first part of the query object ( campaign_id ) : stats.collectDate isn't taken in account. (i get ALL the records relative to stats.campaign_id : result length > 100 )

From the mongo console, the query work as expected : results are filtered by stats.collectDate (results lenght = 3 ).

Do somebody know how to make the query works also from my node app, possibly without using different modules ? And , what are the difference between mongoconsole and mongo node driver ?

Many thanks in advance

3
  • 2
    Could you show the full code you're using in both cases? Commented Oct 2, 2013 at 11:11
  • Hi, the code is always the same : db.collection.find(queryObject) (the query object is the one in my question) , the problem is that results are different (it seems that query params are ignored from Node). I read somewhere that something change when executing commands from console or from node, but i didn't find anything explaining this. Commented Oct 15, 2013 at 10:00
  • its a bit late, for anyone trying to find answer for nodejs mongodb crud. please find this tutorial. programmerblog.net/nodejs-mongodb-tutorial Commented Jul 14, 2017 at 15:13

1 Answer 1

0

try warp your time stamps in Date Object in your node app

{ 'stats.campaign_id': 6010108824797, 'stats.collectDate': { '$gte': new Date(1375628400), '$lt': new Date(1375632000) } }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.