1

When running checkpoints.js script below

$ mongo -u "admin" -p "xxx" monitor checkpoints.js

it doesn't look like variable 'i' can be used inside db statement ?

for (var i=1; i<8; i++) {
        print(i)
        print(db.checkpoints.find({day: i}).count())
}

Because it prints zeros for me

1
0
2
0
3
0
4
0
5
0
6
0
7
0
3
  • 2
    And if you do db.checkpoints.find({day: 3}).count() it does return a result ? Commented Dec 15, 2015 at 13:38
  • only after I did i.toString(), sorry... Commented Dec 15, 2015 at 13:53
  • That's what I thought, I was just about to suggest .find({day: i.toString()}) but wasn't sure. Commented Dec 15, 2015 at 13:59

1 Answer 1

1

The zero that is printing is the count of your query, not the variable i.

Update

I misunderstood your question, the variable can be used, just check that your query returns non-empty result by running it manually:

db.checkpoints.find({day: 1}).count()
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.