0

I have a db called db1, and a collection called places. If I do:

use db1;

use places;

db.places.find().pretty();

I get the proper results from the collection, but if I load the following javascript file, I do not get any results:

 var query1 = function(){
    db.places.find().pretty();
 };

I'm loading the proper js file, from the correct directory with this command: load('test.js'); I'm actually running mongo in the same directory where the js file is. After loading it and calling the function query1(); I don't get any results. I'm running mongo shell version 2.6.3, Ubuntu 14.04 32 bit; I had a previous version on my old computer which had Ubuntu 12.04 and didn't have this issue when loading js files. Hope you can help me- Thanks!

2
  • 1
    try with return db.places.find().pretty(); in query1? Commented Aug 13, 2014 at 2:39
  • That was it, thank you, it was obvious but also one of those things you forget once in a while Commented Aug 13, 2014 at 2:42

1 Answer 1

1

I think the problem is you are not returning the values from your function.

Just do like bellow

var query1 = function(){
    return db.places.find().pretty();
};
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.