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

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

Related

MongoDB. Studio3T. Mongoose. Hyper returns empty array. Pluralization in naming most likely not the issue

I ran mongod in Hyper Terminal.
I established connection with Studio3T and MongoDB. And created collection and documents in Studio3T. The database, collection, and documents appear in Studio3T and MongoDB. In Hyper the database and collection exist, but the documents are not there. Any idea why?
I have consulted stackoverflow and could not find the answer in the resources listed (sorry if I missed something):
Mongoose always returning an empty array NodeJS
Model.find() returns empty in mongoose
Mongoose always return empty array?
What are naming conventions for MongoDB?
MongoDB:
Mongosh in Hyper:
Studio3T:
Code in Atom:
Run code and result in Hyper:
I started mongod and connected to the MongoDB server locally. My application code pointed to the following:
mongoose.connect("mongodb://localhost:27017/wikiDB");
The above is local. But my data is on the cloud-based MongoDB Atlas Cluster. I shouldn't need to run mongod. So, I changed my application code:
mongoose.connect("mongodb+srv://admin-yourname:password#blahblahblah.mongodb.net/wikiDB");
where yourname AND password AND blahblahblah are specific to the coder.
Now my application code points to the Atlas Cluster where my data is.
Summary:
My data is on the cloud-based Atlas Cluster.
To see my data on the Atlas Cluster from the command line, I "Connect with the MongoDB Shell" and run the connection string that MongoDB provides in the command line. Now I see my data in the command line.
To see my data on the Atlas Cluster when I run my code, I use "Connect your application" and place the connection string that MongoDB provides in my code (the mongoose.connect(....) ). Now when I run my code, I can see my data in my browser or command line if I console.log it.
If you are in the command line and run mongod in one tab, and mongosh in another, and use db.articles.find(), then nothing will appear but an empty array. That's because the data is on the cloud-based Atlas cluster. In this instance, you are viewing things locally.
If your application code points to your local MongoDB server (ran mongod in one tab, mongosh in another), then when you run the code you will see nothing but an empty array because the data is on the cloud-based Atlas cluster. In this instance, you are viewing things locally.

Executing commands from MongoDB Compass

Is it possible to execute a command such as db.eval("return new Date()") from MongoDB Compass?
Right now I see only collection query commands like filter, project, sort, etc.
Mongo compass provides only filter option (Query Bar) to do queries on specific collection :(
You can read how it works - https://docs.mongodb.com/compass/master/schema/#query-bar
Replying to old thread: Just want to mention that Mongo Compass v1.22 and newer has Embedded Shell which can do shell commands https://docs.mongodb.com/compass/current/embedded-shell/

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

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

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

Where to set mongodb start parameter in a meteor application on nitrous.io?

I'm studying meteor and trying some examples on nitrous.io, but the available disk space was soon consumed by the big mongo data files (including the prealloc journal files).
Unfortunately MongoDB is also new to me. I googled around and found that I can start mongoDB with some parameters like --nojournal, but I have no idea where in the nitrous.io app I can pass this parameter to mongodb at startup?
I also can't find any mongodb.conf (even *db.conf) to use the storage.smallFiles setting.
Any help would be appreciated!
Instead of using Meteor's builtin MongoDB instance, you can specify a custom instance (which you can configure the way you want).
To do this Nitrous.IO, you can follow these steps:
Create a box with Meteor template.
Install MongoDB, by running parts install mongodb (Autoparts is Nitrous.IO specific package manager)
Open the MongoDB config located at /home/action/.parts/etc/mongodb.conf
Tweak it to your liking.
Start MongoDB instance by running parts start mongodb
Now you can create a new meteor project - meteor create projectname
Finally, when you're starting meteor on your project specify the MONGO_URL environment variable. eg: MONGO_URL=mongodb://0.0.0.0:27017 meteor.
Hope this would be good enough to get started. You can also upgrade your Nitrous.IO account to increase the storage of your box.
UPDATE: I just noticed that Meteor runs its MongoDB instance with --smallfiles flag set.