Skip to content

Instantly share code, notes, and snippets.

@oliverwebr
Created November 13, 2017 23:07
Show Gist options
  • Save oliverwebr/589d595477ecf97c8960bbe32bd98dc0 to your computer and use it in GitHub Desktop.
Save oliverwebr/589d595477ecf97c8960bbe32bd98dc0 to your computer and use it in GitHub Desktop.
Short MongoDB vs MySQL query syntax

Battle of the Giants

This guide is a short form of MongoDB and MySQL Compared from mongoDB

Inserting user with (id, age, status)

MongoDB

db.users.insert({
  user_id: 'bcd001',
  age: 45,
  status: 'A'
})

MySQL

INSERT INTO users (user_id, age, status)
VALUES ('bcd001', 45, 'A')

Get all Users

MongoDB

db.user.find()

MySQL

SELECT * FROM users

Update user based on age

If the user is older then 25 we want his status to be 'C'.

MongoDB

db.users.update(
  { age: { $gt: 25 } },
  { $set: { status: 'C' } },
  { multi: true }
)

MySQL

UPDATE users SET status = 'C'
WHERE age > 25
@oliverwebr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment