Lab 4 - Querying Oplog

I got the right answer for lab 4, but can anyone demonstrate how one can query the oplog to confirm that it was not a write concern? They show they in the answers, but I don’t see anywhere in the lectures where it discusses querying the oplog.

The oplog can be found in the local database and you can query it from there:
use local
db.oplog.rs.find({}).limit(3).pretty()

Thanks! Where would you see if it’s using a write concern or not?

I believe you just need to query it to find the statement that was passed. For example, if the db is called m312 and the collection is called categories, you could find one of the operations like so:
use local
db.oplog.rs.find({"ns": "m312.categories"}).limit(3).pretty()

… and you can add criteria to the “op” field to find the writes. I know that “i” is for inserts.

@Travis_55422 I’ve just tested it out and it turns out that the oplog doesn’t contain options applied to an insert operation. I had to use the Database Profiler with a profiling level of 2 to get this info:

  1. Check profiling level
    db.getProfilingLevel()
  2. Set profiling level
    db.setProfilingLevel(2)
  3. Perform an insert operation that contains a Write Concern
  4. Turn off the profiler
    db.setProfilingLevel(0)
  5. Query the profiled data:
    db.system.profile.findOne({"ns": "database.collection", "op": "insert", "command.writeConcern": {$exists: true}})

… replace database.collection with the name of your database and collection respectively.

However, as you already know, the profiler is not recommended in a production environment. :warning: