Sunday, June 17, 2018

MongoDB versus MySQL Document Store Command Comparisons III

This time we will look at the differences in updating records between MongoDB and the MySQL Document Store.  Syntactically they are pretty different.  I am still following the Getting Started With MongoDB article for example queries.

Updating Records

In Mongo we update thusly:
> db.restaurants.update(
... { "name" : "Juni" },
... {
...  $set: { "cuisine" : "American (new)" },
...  $currentDate: { "lastModified" : true }
... }
... )
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

The same update in the MySQL Document Store can be a lot different.  We could update using SQL or NoSQL.  I would like to update the document with the change to the cuisine and set the last modified to the current data.  The first change is pretty simple:

db.restaurants.modify("name = 'Juni'").set("cuisine","American (new)")

 But what about that last modified value? Well, that on the SQL side would the values of now() but the MySQL NoSQL side does not have that concept, at least it is not documented.  And lastModified is not in the document itself?!?!  Is it metadata hiding somewhere and hiding somewhere in the Mongo documentation??

Well, after some frustration with searching for document metadata and timestamps with Mongo documents, I decided to circle back to this later.

Updating Embedded Fields

The updating of embedding fields can be as mess but both products can handle  this operation.  The Mongo version is:

> db.restaurants.update(
... { "restaurant_id" : "41156888" },
... { $set: { "address.street": "East 31st Street" }}
... )

And the MySQL Document Store's version:

db.restaurants.modify("restaurant_id ='41156888'").set("address.street","East 31st Street")

So both do what is wanted but have much different syntax.

Updating Multiple Documents

Changing multiple records can be tricky, especially for novices or those learning new software.  Usually it is best to run the SQL version of the old  MySQL shell in --i-am-a-dummy mode for novices where forgetting a WHERE clause can be disastrous.  But the new MySQL shell does not have this option and Mongo forces you to expressly state you want to change multiple records.  Here is a distinction between the two products:

> db.restaurants.update( 
   { "address.zipcode" : "10016", "cuisine" : "Other"}, 
   { $set: { "cuisine" : "Category to be determined"}},
   { multi: true }
WriteResult({ "nMatched" : 20, "nUpserted" : 0, "nModified" : 20 })

Mongo will update only one record unless multi is set to true.  If not set you will get only one record updated. 

MySQL has no such limitation and will change multiple records. 

db.restaurants.modify('address.zipcode = "10016" and cuisine = "Other"').set('cuisine','TBD')
Query OK, 20 items affected (0.2997 sec)

I am also a fan of the explicit and in the MySQL query and not much of a fan of the implied and in the Mongo query. Why? When you try to debug things at two in the morning it is very easy to assume an or or other comparison operator.  When you program assembler you get picky about things like or, xor, and ands.

Picking Output Keys

You may not want all the keys and values from a document every time you dive into the data. Specifying specific keys again shows the differences in syntax between the two products

 > db.restaurants.find( { "name" : "Pizza Plus" }, 
   { name : 1 , borough : 1})
{ "_id" : ObjectId("5b2293b4f46382c40db8264f"), "borough" : "Brooklyn", "name" : "Pizza Plus" }
{ "_id" : ObjectId("5b2293b6f46382c40db86fb0"), "borough" : "Manhattan", "name" : "Pizza Plus" }
{ "_id" : ObjectId("5b2293b6f46382c40db8854b"), "borough" : "Brooklyn", "name" : "Pizza Plus" }

You get the _id if you want it or not. MySQL only gives you the desired values for the specified keys.


db.restaurants.find('name = "Pizza Plus"').fields('name','borough')
        "borough": "Brooklyn",
        "name": "Pizza Plus"
        "borough": "Manhattan",
        "name": "Pizza Plus"
        "borough": "Brooklyn",
        "name": "Pizza Plus"
3 documents in set (0.0486 sec)

So those extra characters are not so bothersome with small data sets but when you have millions of lines or more that extra really add overhead.



  1. My Assignment Services provides a 24-hour online Assignment Help and consultation to the students. Be it any subject such as Nursing, Economics, Law, Engineering, or Management, we provide the most reliable help with assignment online by our highly-proficient academic writers. My Assignment Services constantly aim to expand our base of assignment writing experts and call in international experts who are ex-professors from reputed business schools, management schools, engineering universities from across the globe. This provides you with an opportunity to get a global and world perspective in your Assignment Help UK answers and lets you connect with a writer who understands you. This company has been trusted by thousands of students in Australia for their incredible help with assignment that are provided to students worldwide. Join these thousands of students and achieve high distinction in each and every one of your college tasks. We are proud of our best assignment help experts because of their dedication towards providing continuous support to students by helping them meet deadlines and scoring better grades. We understand how important academic assessments are in developing a student's career and future opportunities, this is why we take extreme measures to ensure that all University Assignment Help solutions are best-in-class.

  2. This post is quite striking and helped me to gain deep understanding of some of my academic topics. I would recommend everyone to choose Assignment Help Australia. You can email us at cs@Myassignmenthelpau.Com or Phone Number: +61-2-8005-8227

  3. Our our team is working with you with every academic discipline that you face troubles in. Some time english home work is tough academic task that is not possible for all the student to finish it accurately. So the online helpers at is offering its excellent English Homework Help services and make their academic life easy.

  4. Students are facing problems in write assignment. We provide our service at assignment help Melbourne. Our experts are check two times all of the works then send to students. Our experts have many experiences in the writing field. Book Now!

  5. We are proud of our best Assignment Help Singapore experts because of

    their dedication providing continuous support to students by helping them meet deadlines and scoring better grades. We

    understand how important academic assessments are in developing a student's career and future opportunities, this is why

    we take extreme measures to ensure that all our solutions are best-in-class. All students looking for assignment help

    Singapore can reach us and avail the best online javascript assignment help from our academic experts.
    Our primary motive is not only to provide you with the best help but also to make your journey smooth. The increasing

    importance of writing assignments has prompted students to take a helping hand from assignment writing services. During

    higher studies in colleges, students often have to prepare multiple documents, quizzes, and surprise tests. This is the

    main reason why most students search for australian assignment help

    over the internet and choose only the most proficient and trusted academic writing experts.

  6. Guys, in this post you may learn how to track your girlfriend’s phone to find proves she is cheating.

  7. We are proud of our best Assignment Help Australia by experts because of their dedication towards providing continuous support to students by helping them meet deadlines and scoring better grades. Hiring an expert to write your work is easy but hiring the RIGHT expert to get it done is a challenge. This is because there are a multitude of assignment help australia services and picking the best is always going to be a trial and error method. In case of engineering and pure sciences, the data analysis’ initial three/four steps remain the same. We have some of the best Engineering Assignment Help who have intensive knowledge of wide range of topics as discussed above and beyond. They feel completely pressurized. He starts disliking his school or college. But may come, he has to submit his assignment before the deadline, therefore he chooses to buy assignment services available to him. To help students complete their assignments Gotoassignmenthelp is here to serve them with the best assignment help.

  8. Gotoessayhelp is a round the clock essay help service which caters solutions request to various subjects’ tools & methodology in a multi environment learning concept for the subjects like essay help online. We are a renowned service provider of essay assignment help and have been receiving an overwhelmed response globally.
    We offer plagiarism free, original content to our clients and facilitated are clients to grow their career by using the services of our proven Ph.D. experts, as we understand how important grades for students within their academic purview. u will experience a hassle-free service and top-class quality.

  9. yes!l can do it!we are the KNTECH,we can provide the ip pbx system and ip pbx software.

  10. Are you looking for the online assignment writing in London so that you can grab good attention. We will deliver you the world's best quality assignment help give priority to the needs of every student. Get connected with us and give us the chance to provide you with better service.

  11. AbAssignmentHelp provides online assistance to complete your assignment, and they guarantee you the lowest possible price of assignment help with unmatched quality of assignment in the UK.

  12. Looking for guest posting websites? Allremark is the best site here you can write a post on all niche and submit it to our website if that content fulfill our guidelines then we will publish that content on our website.

  13. Thanks for your inspired content, GreatAssignmentHelp is a right online way for all your PHP Assignment Help. Our educator and professor provide best guidance to both the Masters and Bachelor candidate. Professionals who working with us have a solid knowledge of Advanced and basic PHP. In addition, We continue update our professor about the new technology in the field of programming, we continue upload our researched technology and student career oriented blogs, articles, and journals. It assurance that you get the best help and rank nothing less than top.
    PHP Assignment Help
    PHP Programming Help

  14. We focus on meeting all the needs of our clients by offering them with a reliable custom essay writing service USA and legitimate paper writing services delivering it on time.