Shell logging for mongodb - 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.

Related

mongo' is not recognized as an internal or external command, operable program or batch file

mongo is not recognized as an internal or external commandmongodb is not recognized as an internal or external commandI'm encountering these errors after having installed mongodb using a tutorial and after having tried the edit environment variables fix.I've edited the environment variables The mongosh keyword is recognized when I type it in in the command line but mongo and mongodb aren't. Mongod results in something I'm not certain it should be resulting in.is this expected? I noticed that the number of files available in my bin folder which is where mongodb is installed is less than that of others that I've seen.this is my bin folder with less files I also noticed that after installing mongodb, the mongo compass didn't auto install. I did that manually. How can I overcome these errors and start using mongodb?
mongod is the binary that runs the database. It has many flags, documented here. The output you see is expected. You will often run this in the background via --fork and send the output to a logfile.
mongo is the legacy shell that is deprecated as of 6.0 and no longer ships.
mongosh is the new shell that should provide all the same functionality as the legacy shell.
mongodb there is no binary with this name.
If you are trying to connect to MongoDB Atlas or an existing database, you should not need to run mongod yourself.

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

How to enable auditing in mongodb for windows environment

I would like to enable auditing feature for mongodb in windows environment. As per mongodb documentation Configure Auditing we cannot use audit parameters like --auditDestination in windows. Is there an alternate way to enable auditing in windows. My requirement is whenever there is DML operation in mongodb i need to capture in a audit table for changed records. Any help is much appreciated.
Audit events are only available in MongoDB Enterprise and not the Community edition (as of version 3.2) .
But what you mention here is not what the documentation says. MongoDB allows for 4 different destinations for audit events (again as of version 3.2) . It only says one of the following 4 options is not available in Windows.
syslog: This is not available in Windows.
console: prints the audit events to the console.
mongod --dbpath data/db --auditDestination console
JSON file: prints the audit events to a JSON file.
mongod --dbpath data/db --auditDestination file --auditFormat JSON
--auditPath data/db/auditLog.json
BSON file: prints the audit events to a BSON file.
mongod --dbpath data/db --auditDestination file --auditFormat BSON --auditPath data/db/auditLog.bson

How to run a mongod instance

I am a starter of MongoDB. According to the "Import Example" section of MongoDB 3.2 Manual, the prerequisite for importing data into the database is to have a running mongod instance. With limited background knowledge of MongoDB, I failed to fully understand this line of instruction. Could anyone please give me some explanation on how to run a mongod instance step by step in Mac Terminal? Thanks.
Here are several steps to do start mongodb var mongod
created the ./bin/data/db directory storing mongodb data file.
Start one terminal for mongodb server
Go to mongo/bin, and execute this command
./mongod
Start another terminal for mongodb shell
Go to mongo/bin, and run
./mongo
Now we can connect to mongodb now, more command like show dbs, show collections, use dbname, For more commands in mongodb, refer to db.help()...

Unable to launch Mongo Db Shell

I have downloaded mongoDb binary distribution from URL "http://www.mongodb.org/dl/win32/x86_64-2008plus-ssl" and extracted it in my C drive ( Windows 7). But I am unable to access mongo shell using the mongo command. I downloaded node.js binary version and used the same method and it ran successfully. I want to ask if there is a way to run mongo db using the binary distribution. I don't have admin privileges. Any help in this regard is welcome.