How can I find a meteor mongodb collection from the shell? - mongodb

When I go into "meteor mongo" OR "mongo localhost:3001", a shell opens up. If I 'show dbs', it displays:
customers 0.000GB
local 0.008GB
meteor 0.002GB
I created a collection during tinkering from within the shell and that currently is visible. What isn't visible, however, are the several collections that exist in my app! For example, in my meteor app, from localhost, I get a return of documents when I type 'Jobs.find().fetch()' and 'Tasks.find().fetch()'. If I update these documents, it persists after the app has been restarted.
These collections DO exist, but I don't know how to access them via shell.

You can access your collections like that:
> use meteor;
> db.myCollection.find();

try using robomongo. remember first to have meteor running

Related

Mongodb not listing collections when connecting remotely from CentOS

Mongo server: Windows 10 (host)
client: CentOS 6.2, a virtual box vm on windows 10 host. This is actually a cloudera quick start vm.
Issue:
mongodb connects to the remote server (from CentOS to Windows) via terminal, lists the databases fine, but 'show collections' just returns blank. That said, the collections are accessible because I can query any collection and the count also gives me the correct results.
On the other hand, I have connected to the same mongo server from IntelliJ and it shows all the collections just fine.
Just curious as to why this is happening.. Any comments?
Side Note: is there a mongodb command to count the number of collections in a database?
Thanks
_Vamsi
Make sure you are using the database you want to show the collections for. You may be using a database that doesn't have any collections.
> use desiredDatabase
> show collections
If the list is still empty, try signing in with an admin user account. The user needs to be able to perform the listCollections action. The dbAdmin role includes the listCollections action.
To get the count you can use the getCollectionNames function which returns an array and you can get the length from that.
> db.getCollectionNames().length

how to show my users collection with mongodb

I'm sorry for this (peraphs) stupid question ... I install meteor and mongodb in my windows computer and i start to write some apps. I don't understand how to use mongo for shoving my db app ... i open one shell in my app dir and launch mongod, in one more shell in the same folder i start mongo.
show dbs
local
use local
switched to db local
show collections
startup_log
system.indexes
Where are my collections? Where is users collection?
When your app is running use this command on a separate command line mongo 127.0.0.1:3001
Meteor keeps the collections in this server. After you run mongo on this server, by writing use meteor you can use db specific to your running app. And then you can display your collections with db.getCollectionNames()
Meteor uses a library called Minimongo that's why it doesn't display if you run show dbs on your mongo shell.
By default it points to port 3001 hence if you are using Robomongo you can just make the set up to watch that port.
To display all your MongoDB collections using the shell, you may check this answer:
How to list all collections in the mongo shell?
You may also use a MongoDB GUI Tool such Robomongo

How can I query an FS collection in Meteor from the command line?

It is very useful to run meteor mongo and query collections from the command line, for debugging purposes, etc.
Recently, I have added the collectionFS package to enable image storage in the database. However, I am unable to query the database from the command line.
db.fs.collection_name.find() is not doing the trick, and I can't seem to find the correct command anywhere.
Go to the Meteor Mongo console: meteor mongo
See all the collections that are available: show collections
Look for the one that has cfs.collection_name.files
Choose the one that has your collection name. For example, I'm using collectionFS with gridFS for images. When I type show collections, I see cfs_gridfs.images.files so I just do: db.cfs_gridfs.images.files.find() to see those files.
Hope that helps.
If you find it difficult to use the command line or terminal, you have a UI for MongoDB called Robomongo which is easy to install and use. I use Meteor with its default port number and then in Robomongo it is used as 3001.
And the query to view collection here is same as db.collection_name.find().

How to perform something like meteor reset on deployed app?

I have an app deployed on digital ocean and am trying to perform a meteor reset to reset the DB etc. Where is meteor located when deployed via mup? I keep getting a command not recognized with meteor commands.
As far as I know you can't run meteor reset on deployed apps like that as it's already been built by MUP. The way you could mimic a meteor reset is to run the mongo shell on your digital ocean server:
mongo
You can check what the databases are by using:
show dbs
and then access the one meteor is running by doing:
use [db name]
and then manually drop the databases by using:
db.[collection name].drop()
http://docs.mongodb.org/manual/reference/method/db.collection.drop/
Meteor already has the user collection defined so you'd probably want to drop that collection too if you want a clean start

When using a separate MongoDB with meteor, meteor reset stopped working

I have my MONGO_URL set to mongodb://localhost:27017/meteor and have the MongoDB run as a service.
When running my project it seems OK to store data to the separate MongoDB until I tried to run meteor reset.
My assumption is it tried to remove its default database. The error complained that myproject.meteor\local is not empty and pointed to fs.js:456 which goes to files.js:256 (rm_recursive) and so on.
any idea what and how I can fix this?
$ meteor reset only resets the bundled MongoDB. It won't reset an external Mongo database.
(That's something we should explain better in the documentation.)
In your case, try connecting to the Mongo database directly (with the mongo command line shell) and running > db.dropDatabase()