Monday 4 May 2015

MongoDB M101N Final Exam Question 3

Question 3:

In this problem, the database will begin in an initial state, you will manipulate it, and we will verify that the database is in the correct final state when you click 'submit'. If you need to start over at any point, you can click 'reset' to re-initialize the database, but this will not change your answer if you have already clicked 'submit'. If you wish to change your answer, get the database into the correct state, and then click 'submit'. If you leave the question and come back, the database will re-initialize. If you have clicked the 'submit' button at least once, you will see the word "Submitted" below the shell.
 
In this problem you will update a document in the messages collection to illustrate your mastery of updating documents from the shell. In fact, we've created a collection with a very similar schema to the Enron dataset, but filled instead with randomly generated data.



Please add the email address "mrpotatohead@10gen.com" to the list of addresses in the "headers.To" array for the document with "headers.Message-ID" of "<8147308.1075851042335.JavaMail.evans@thyme>"

 
Solution: 

As we have add an email id in "To" array, we will use $push keyword as below


db.messages.update({'headers.Message-ID':'<8147308.1075851042335.JavaMail.evans@thyme>'}, {$push : { 'headers.To' : 'mrpotatohead@10gen.com'}} ) 

No comments:

Post a Comment