0

I am trying to create some mongoDB script (files upload to collections, find, create new collections etc). Though get confused. When I run in console:

> use importCSV    
> db.people.find().pretty()

I get documents from collection on my screen, though when I run load command

> load('e:/work/parse/script.js')

i get output

true

Here javaScript file list

db = db.getSiblingDB('importCSV');
db.people.find().pretty();

I do it for debug purpose, so I create javaScript line by line to get what I want, and I need to see step by step some commands output. If I put to javaScript file command like this

print('Print from javaScript file');

it prints to console without any problems.

Why I get "true" when run from file instead of console output, and how to get list of documents printed when run from javaScript file?

Thanks

2
  • what is your question? Commented Oct 22, 2015 at 16:42
  • You right :) Edited! Commented Oct 22, 2015 at 16:45

1 Answer 1

2

This is an expected behaviour. You need to iterate through the cursor and print each document explicitly using a .forEach loop because you are not using the interactive shell.

db = db.getSiblingDB('importCSV');
db.people.find().forEach(function(doc) {
    printjson(doc);
}
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.