Question

I have few problems with meteor. Is there any need to create database using "use mydb" programmatically. I didn't used it so far and i'm directly creating collections and applied CRUD operations on them. But, i saw db.collection.find() like things few times and when i'm trying to apply on my collection it is showing error like db is not initialized how to initialize it. Here my main problem is, I tried to import some content from .json file to my collection. which is possible using database only(i thought). I can import them from shell like this

mongoimport --db test --collection mobiles <products.json --jsonArray

and how to import them without db.

Was it helpful?

Solution

You would have to show some code to see what exactly the issue is.

Meteor uses MongoDB so the schema doesn't need to be strictly created for things to work, like as would be done in MySQL or a traditional SQL type database. You can just insert documents and if the collection doesn't exist, or the database doesn't exist it would be created then without explicitly being created separately.

To import your files you need to import to your meteor database running at port 3002 (if your meteor app is running on port 3000 - meteor app port + 2). Something like this should work, the database is meteor

mongoimport --db meteor --host localhost:3002 --collection mobiles --jsonArray --file production.json

(Not sure about your file structure so i'm assuming its --jsonArray --file production.json). You could check out the docs at http://docs.mongodb.org/v2.4/reference/program/mongoimport/ for more details

So again you wouldn't need to create a database when you do this, using the --db argument would load things into meteor. If it doesn't exist it would automatically create it as you use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top