How to enable auditing in mongodb for windows environment - mongodb

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

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.

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.

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

Data storage in mongodb

first of all please forgive me for asking a silly question but I am new to mongodb and just installed it on my windows platform by following this installation guide :http://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/
It says "MongoDB requires a data folder to store its files. The default location for the MongoDB data directory is C:\data\db.You can specify an alternate path for data files using the --dbpath option to mongod.exe."
So I created a folder d://data/db in my computer and issued a command
C:\mongodb\bin\mongod.exe --dbpath d:\mongodb\data
Then it says
"At the mongo.exe prompt, issue the following two commands to insert a record in the test collection of the default test database and then retrieve that record:
db.test.save( { a: 1 } )
db.test.find()"
I issued this to commands to save and retrieve the objects and its working fine but what is this default test database? where is it? Moreover where this object is stored? Where I can find this file?
what is this default test database?
When you connect to a mongod server without specifying a database, a default database "test" is selected. Since databases are created lazily, it may not even exist until you write to it.
db.test.save( { a: 1 } )
After this line is executed, database with current name ("test" by default) is created (if didn't exist already) and in it, collection "test" is created (if didn't exist already).
where is it? Moreover where this object is stored? Where I can find this file?
All databases are ultimately stored as files in your data dir. Look for "test.*" files there.
mongod.lock, is the file which provides the PID of your running mongod instance. When you start a mongod instance, MongoDB check if the lock is empty to start cleanly mongod. Then MongoDB registered the PID number of the running mongod instance in this lock file.
MongoDB delete the contains of this lock file when you shutdown cleanly your server,
mongod --shutdown -- dbpath <path name> --port <port number>