Can't retrieve MongoDB collection in Git Bash (Windows) - mongodb

This is the exact steps that I followed:
User#User-PC MINGW64 /
$ mongo
2016-02-22T10:02:33.474+0800 I CONTROL [main] Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.2.3
connecting to: test
use dev
switched to db dev
show collections
Building
_SCHEMA
db.building.find()
After doing db.building.find nothing outputs; no error, nothing.
Maybe I'm trying to fetch the collection in the wrong way?

The collection name is Building, so please try
db.Building.find({})
rather than
db.building.find()

Related

Shell logging for mongodb

I am new to mongodb and trying to figure out a lot.
Can we configure shell logging for mongodb? What I mean is the capability to get logs from the Shell to track queries for auditing purposes for version 4?
If so - what commands do we have to run please?
Thank you for your help
There are two versions of MongoDB shell: the newer mongosh and the older/legacy mongo shell.
mongo maintains a history of commands in the .dbshell file. For example, in the Windows 7 environment this can be found at the folder: C:\Users\<user_name>
MongoDB Shell mongosh stores logs for each session and can be retrieved as explained at: Retrieve Shell Logs. For example, in Windows environment this can be found at the folder: C:\Users\<user_name>\AppData\Local\. The log files are of the format <LogID>_log.

How do you convert mongod to mongo service?

I have been running MongoDB on two Windows 10 PCs. However, one has mongo always running it seems where I only need to open command prompt and type mongo. This gives me access to the db on PC #1.
However, on PC #2, I must open command prompt and type mongod. Then I have to open a second command prompt to type in mongo, then I get access to the db on PC #2.
After doing this for about a year, I find I want to just want both PCs to work like PC #1, where I just type in mongo and not mongodb and only have to use one command prompt.
I checked online but there's nothing I found straightforward to accomplish this specifically.
Does anybody know the answer?
If in PC#2, your MongoDB version is < 4.0, then you can't do anything i.e., you have to continue with mongod to start Mongo as you do now.
But if your MongoDB version is >= 4.0 or you want to upgrade from lower version of MongoDB, you can follow the below steps.
Take backup of all databases with mongodump. If it is large volume data, then go through this.
Uninstall your MongoDB using Windows Uninstall Program features.
Reinstall MongoDB using the link.
While installing, ensure you select 'MongoDB Service' feature.
Start the MongoDB now in PC#2 as you do in PC#1.
Restore the old databases with mongorestore.

mongodb 3.2.11, version too new for this mongod

I have an issue with mongodb server. I am using version 3.2.11.
Unable to find metadata for table:index-3--5957523542490303670 Index: {name: id, ns: dashboard.dataaas} - version too new for this mongod
I have already update mongo version to 3.4, but it still could not start the server on, the error still remains.
I would like to delete that index / table, but I could not log in to mongo-shell. And could not found file index-3--5957523542490303670 in any of folder
Please help
Basically as error states, mongo client/shell as well as mongod server should have the same version. You can check the mongo shell version using mongo --version. If it does not match, downgrade/upgrade client as required.
Also check if server is running.

mongodb - command 'show collection' doesn't show anything

I switched my db properly and also confirmed that there is a document in my collection but I cannot find any collection by 'show collection' command.
Can I know the reason?
Please check your Mongo shell version and MongoDB version are compatible.
Refer to this JIRA ticket which has the similar issue reported. The root cause of the problem was the Mongo shell version and MongoDB version were not compatible.
To get Mongo Shell version:-
Go to the bin folder and execute mongo command which will print the Mongo shell version in the first line.
To get MongoDB version:-
db.version()

Roles missing in mongodb

I am using Docker to add mongodb 2.6.5 to a host that already had 2.4.9 installed and I am sharing the data directory.
When I run the 2.6.5 (in container) I get permission issues apparently due to changes in 2.6:
http://docs.mongodb.org/manual/tutorial/add-user-to-database/
But when I try to add a user with role roleAdminAnyDatabase I get "No role named roleAdminAnyDatabase#admin"
Do I need to migrate the data? What is the best way to do that?
I assume I could start up 2.6.5 with no data files and mongorestore the data from 2.4.9. But, does that mean I cannot run 2.4.9 using that directory anymore?