SQL to Mongo Mapping Chart
MySQL executable | Oracle executable | Mongo executable |
mysqld | oracle | |
mysql | sqlplus | mongo |
MySQL term | Mongo term/concept | |
database | ||
table | ||
index | ||
row | BSON document | |
column | BSON field | |
join | ||
primary key | ||
group by |
MongoDB queries are expressed as JSON (BSON) objects. The following chart shows examples as both SQL and in Mongo Query Language syntax.
The query expression in MongoDB (and other things, such as index key patterns) is represented as JSON (BSON). However, the actual verb (e.g. "find") is done in one's regular programming language; thus the exact forms of these verbs vary by language. The examples below are Javascript and can be executed from the mongo shell.
SQL Statement | Mongo Statement |
CREATE TABLE USERS (a | implicit; can also be done explicitly with
|
ALTER TABLE users ADD ... | |
|
|
INSERT INTO USERS VALUES(3,5) |
|
|
|
SELECT a,b FROM users |
|
SELECT * FROM users |
|
SELECT * FROM users WHERE age=33 |
|
SELECT a,b FROM users WHERE age=33 |
|
SELECT * FROM users WHERE age=33 ORDER BY name |
|
SELECT * FROM users WHERE age>33 |
|
SELECT * FROM users WHERE age!=33 |
|
SELECT * FROM users WHERE name LIKE |
|
SELECT * FROM users WHERE name LIKE |
|
SELECT * FROM users WHERE age> |
|
SELECT * FROM users ORDER BY name DESC |
|
SELECT * FROM users WHERE a=1 and b='q' |
|
SELECT * FROM users LIMIT 10 SKIP 20 |
|
SELECT * FROM users WHERE a=1 or b=2 |
|
SELECT * FROM users LIMIT 1 |
|
SELECT order_id FROM orders o, order_line_items li WHERE li.order_id=o.order_id AND li.sku=12345 |
|
SELECT customer.name FROM customers,orders WHERE orders.id= |
|
|
|
SELECT DISTINCT last_name FROM users |
|
SELECT COUNT(*y)
|
|
SELECT COUNT(*y)
|
|
SELECT COUNT(AGE) from users |
|
|
|
CREATE INDEX myindexname ON users(name) |
|
CREATE INDEX myindexname ON users(name,ts DESC) |
|
|
|
EXPLAIN SELECT * FROM users WHERE z=3 |
|
|
|
UPDATE users SET a=1 WHERE b='q' |
|
UPDATE users SET a=a+2 WHERE b='q' |
|
|
|
DELETE FROM users WHERE z= |
|
More examples, specifically aggregation examples, here
See Also
- The MongoDB Manual Pages are a good place to learn more.
- SQL to Shell to C\+\+
'Computer Science' 카테고리의 다른 글
Visual studio 2010 에서 소스파일을 UTF-8 로 자동변환 (0) | 2012.08.19 |
---|---|
HTML5로 자신만의 3D 엔진을 만들자 (0) | 2012.07.29 |
튜닝방법론(문제 SQL 분석) (0) | 2012.07.19 |
phpmyadmin과 비슷하게 mongoDB를 php 서버로 관리하기 위한 phpMoAdmin (0) | 2012.07.15 |
자동화된 개발 환경 파이썬 장고 p40120.pdf (0) | 2012.06.15 |