Wednesday 6 May 2015

MongoDB M101N Final Exam Question 6

Question 6:

Suppose you have a collection of students of the following form:
{
 "_id" : ObjectId("50c598f582094fb5f92efb96"),
 "first_name" : "John",
 "last_name" : "Doe",
 "date_of_admission" : ISODate("2010-02-21T05:00:00Z"),
 "residence_hall" : "Fairweather",
 "has_car" : true,
 "student_id" : "2348023902",
 "current_classes" : [
  "His343",
  "Math234",
  "Phy123",
  "Art232"
 ]
}

Now suppose that basic inserts into the collection, which only include the last name, first name and student_id, are too slow (we can't do enough of them per second from our program). What could potentially improve the speed of inserts. Check all that apply.



Options:


  • Add an index on last_name, first_name if one does not already exist. 
  • Remove all indexes from the collection, leaving only the index on _id in place  
  • Provide a hint to MongoDB that it should not use an index for the inserts 
  • Set w=0, j=0 on writes 
  • Build a replica set and insert data into the secondary nodes to free up the primary nodes.    
Solution: 

  After every insert, update, or delete operation, MongoDB must update every index associated with the collection in addition to the data itself. Therefore, every index on a collection adds some amount of overhead for the performance of write operations

In general, the performance gains that indexes provide for read operations are worth the insertion penalty. However, in order to optimize write performance when possible, be careful when creating new indexes and evaluate the existing indexes to ensure that your queries actually use these indexes.

  1.  Is not correct, as adding an index impose overhead on insert operation, although it will surely improve read opertation
  2.  Correct, as stated above
  3.  Is not correct, as there is no way to tell mongo db to temporarily disable indexes (hint is used to assert mongo database engine to forcefully use the given index and not to disable it) 
  4. Correct, as there will not be any overhead of waiting for the write acknowledgement.
  5.  Is not correct, as it is not possible to write on secondary nodes 

No comments:

Post a Comment