Accessing the default mongodb database through console - meteor

Started meteor+mongodb yesterday so probably it is a simple thing:
When we create a new project with meteor create appname and then run it with meteor run Meteor automatically creates a simple project for us, right? (that simple app with a button and a counter).
Ok, based in the fact that all meteor project has his own mongodb associated, how can I take a look on the default db created? I´d like to use a command on console to check the collection structure created by default..
I´ve tried: show dbs | show collections | Mongo.Collection();
But always get the same error message: use "new" to construct a Mongo.Collection.
Yeah, I know that. I know how to create a new mongodb and then create a collection and insert values on it.
But what about that counter that is already working? It´s storaging his values in a collection already created, right?
I´d like to access it... and maybe modify.. not create one db for my own at this moment... How can I do that?
Thanks

meteor mongo command gives you access to mongo console.
From official documentation:
meteor mongo
Open a MongoDB shell on your local development database, so that you
can view or manipulate it directly.
...you must already have your application running locally with meteor run.
http://docs.meteor.com/#/full/meteormongo

Related

React native doesn't see new table in sqlite

I'm using a sqlite database linked to my react-native app.
I've already done some queries in my app that work fine, so the query method is good.
Now, I've add new table to the database by adding a csv file in it (as I've already done before).
But when I make a call on the new table, the console tells me that there is 'no such table'.
If I put the sql query in my DB manager, the call do works.
Thanks for your help!
I did find the solution.
It is very simple, just create a new emulator and rerun your app. It seems that Android Studio works on a 'copy' of the project so it does not see the modification in the database.

Code First and Existing Database with Data

I'm developing a windows application which uses SQL Server Database. I have different versions of this application and they have different database structure, so I need to migrate database to the latest version on application start. I want to compare the database structure with the application model, then do alter, create or drop commands.
Also I want to use EF Code-First ORM, after some search I've figured it out that there are some useful commands and configs in code first. But the problem is, as I know, all of them drop the existing database and create a new one so the data will be lost while I need the data.
I used these lines in my application start function:
var migrator = new DbMigrator(new Configuration());
migrator.Update();
But after execution this line I will get this exception:
There is already an object named 'SomeTable' in the database.
I know that, it's right and there is that table but in structure is changed! How can I compare the structure and do the rest?
That's not how migrations work. You need a migration for every version of your database so EF can check the __MigrationHistory table and see if it has been applied. If your initializer is set to MigrateDatabaseToLatestVersion your database won't be recreated on model changes.
You could try to recreate the history: roll back to your oldest database, add a migration, add 2nd oldest version changes, create a 2nd migration, etc.
Another option is to add a migration for where you are now, generate a script (update-database -Script) then comment out the stuff that exists in each deployed database before applying it.
Yet another option would be to use the VS Schema compare utility against each database and your current database to get the changes over. Then apply a baseline migration to each (add-migration Initial -IgnoreChanges).
Now moving forward you can generate a series of migrations and your code should work as expected.

Meteor, Is there any need to create database using "use mydb" programmatically?

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.
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.

How to perform specific operations during installating or updating a TideSDK app?

I went thru the docs but couldn't find how can I perform specific operations when app is being installed or when app is being updated.
What I want to do is, create table when app is being installed and if in future, db schema changes, I want to perform those operations when app is being updated.
According to me .. the best place to do these changes are in the code. so whenever the application starts up first time after getting updated.. you do all the db schema changes.
This makes sure that your application is fully updated before you touch any database and secondly u do not have to write any special logic separately while installing / updating the application.

Can't use mongo commands in console anymore

I used to be able to use the Chrome Tools Console to type in Mongo commands on my Meteor app and see the results. Stuff like, Collection.findOne({name: "foo"}). It is also done this way in the tutorials on the Meteor site.
Now, for any mongo commands, I just get [collection] not defined. It makes debugging MUCH more difficult.
Perhaps something changed in the last few releases? Any insights?
Since Meteor 0.6.0 individual files are variable scoped. So if you have a collection defined via
var Collection = new Meteor.Collection("collection");
It won't be visible on the console anymore (but it will be visible in the file its defined in)
The workaround is to define the file globally which is just removing the var:
Collection = new Meteor.Collection("collection");
Then you should be able to access it on the chrome js console once again

Resources