0

I new to Mongodb, I tried to find good tutorials but no luck.

2 question:

  1. I have mongo install with data and I want to connect it with js file and play with it I created a.js file and my firs two line were:

    conn = new mongo();

    db = conn.getDB("table1");

and I get error ReferenceError: mongo is not defined at a.js

  1. any good tutorials ?
3
  • Use db.getSiblingDb('table1') and the second question is one left to Google Commented Dec 15, 2014 at 13:02
  • As per the error message, there is no constructor for a mongo object. That should instead be conn = new Mongo() (proper case). For more information on how to write scripts see: Write Scripts for the mongo Shell in the MongoDB manual. Commented Dec 15, 2014 at 13:58
  • While you can write JavaScript code that runs in the mongo shell, note that this is not intended as a full application programming environment. For example, you will have limited control over input & output. If you are just getting started with MongoDB you will probably find it easier to start with one of the supported language drivers (many include tutorials, too). The free online courses at MongoDB University are also a great start. Commented Dec 15, 2014 at 14:04

1 Answer 1

1

I found the answer and it work fine:

conn = new Mongo();
db = conn.getDB("a");
var c = db.getCollectionNames();
print(c);

When I run the file it print all my collection to the shell Thanks.

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.