Skip to content

Commit a20c270

Browse files
committed
DOCS-535 SQL to MongoDB mapping
1 parent af2d3c8 commit a20c270

14 files changed

+903
-17
lines changed

bin/makefile.tables

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
.PHONY: tables clean-tables
55

66
# add each built table to this variable here:
7-
output-tables = source/includes/table-sql-to-agg-examples.rst source/includes/table-sql-to-agg-terms.rst
7+
output-tables = source/includes/table-sql-to-agg-examples.rst source/includes/table-sql-to-agg-terms.rst \
8+
source/includes/table-sql-to-mongo-executables.rst source/includes/table-sql-to-mongo-terms.rst \
9+
source/includes/table-sql-to-mongo-schema-examples.rst source/includes/table-sql-to-mongo-insert-examples.rst \
10+
source/includes/table-sql-to-mongo-select-examples.rst source/includes/table-sql-to-mongo-update-examples.rst \
11+
source/includes/table-sql-to-mongo-delete-examples.rst
812
tables: $(output-tables)
913
@git update-index --assume-unchanged #
1014
@echo [build]: clensing git index of $(output-tables)
@@ -23,4 +27,25 @@ source/includes/table-sql-to-agg-terms.rst:source/includes/table-sql-to-agg-term
2327
source/includes/table-sql-to-agg-examples.rst:source/includes/table-sql-to-agg-examples.yaml
2428
@$(PYTHONBIN) bin/table_builder.py $< $@
2529
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
30+
source/includes/table-sql-to-mongo-executables.rst:source/includes/table-sql-to-mongo-executables.yaml
31+
@$(PYTHONBIN) bin/table_builder.py $< $@
32+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
33+
source/includes/table-sql-to-mongo-terms.rst:source/includes/table-sql-to-mongo-terms.yaml
34+
@$(PYTHONBIN) bin/table_builder.py $< $@
35+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
36+
source/includes/table-sql-to-mongo-schema-examples.rst:source/includes/table-sql-to-mongo-schema-examples.yaml
37+
@$(PYTHONBIN) bin/table_builder.py $< $@
38+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
39+
source/includes/table-sql-to-mongo-insert-examples.rst:source/includes/table-sql-to-mongo-insert-examples.yaml
40+
@$(PYTHONBIN) bin/table_builder.py $< $@
41+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
42+
source/includes/table-sql-to-mongo-select-examples.rst:source/includes/table-sql-to-mongo-select-examples.yaml
43+
@$(PYTHONBIN) bin/table_builder.py $< $@
44+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
45+
source/includes/table-sql-to-mongo-update-examples.rst:source/includes/table-sql-to-mongo-update-examples.yaml
46+
@$(PYTHONBIN) bin/table_builder.py $< $@
47+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
48+
source/includes/table-sql-to-mongo-delete-examples.rst:source/includes/table-sql-to-mongo-delete-examples.yaml
49+
@$(PYTHONBIN) bin/table_builder.py $< $@
50+
@echo [table-builder]: \(re\)generate $@ table for inclusion in build
2651

source/contents.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ MongoDB Manual Contents
1818
use-cases
1919
faq
2020
reference
21+
sql
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# table structure. all content symbolic.
2+
section: layout
3+
header: [ meta.header1, meta.header2, meta.header3]
4+
rows:
5+
- 1: [ content.sql1, content.mongo1, content.ref1 ]
6+
- 2: [ content.sql2, content.mongo2, content.ref1 ]
7+
---
8+
# table metadata, as meta.<key>
9+
section: meta
10+
header1: "SQL Delete Statements"
11+
header2: "MongoDB remove() Statements"
12+
header3: "Reference"
13+
---
14+
# table content, as content.<key>
15+
section: content
16+
sql1: |
17+
.. code-block:: sql
18+
19+
DELETE FROM users
20+
WHERE status = "D"
21+
mongo1: |
22+
.. code-block:: javascript
23+
:emphasize-lines: 1
24+
25+
db.users.remove( { status: "D" } )
26+
ref1: |
27+
See :method:`remove() <db.collection.remove()>`
28+
for more information.
29+
sql2: |
30+
.. code-block:: sql
31+
32+
DELETE FROM users
33+
mongo2: |
34+
.. code-block:: javascript
35+
:emphasize-lines: 1
36+
37+
db.users.remove( )
38+
...
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# table structure. all content symbolic.
2+
section: layout
3+
header: [ meta.header1, meta.header2, meta.header3 ]
4+
rows:
5+
- 1: [ content.desc1, content.sql1, content.mongo1 ]
6+
- 2: [ content.desc2, content.sql2, content.mongo2 ]
7+
---
8+
# table metadata, as meta.<key>
9+
section: meta
10+
header1: " "
11+
header2: "MySQL/Oracle"
12+
header3: "MongoDB"
13+
---
14+
# table content, as content.<key>
15+
section: content
16+
desc1: Database Server
17+
sql1: mysqld/oracle
18+
mongo1: :doc:`mongod </reference/mongod>`
19+
desc2: Database Client
20+
sql2: mysql/sqlplus
21+
mongo2: :doc:`mongo </reference/mongo>`
22+
...
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# table structure. all content symbolic.
2+
section: layout
3+
header: [ meta.header1, meta.header2, meta.header3]
4+
rows:
5+
- 1: [ content.sql1, content.mongo1, content.ref1 ]
6+
---
7+
# table metadata, as meta.<key>
8+
section: meta
9+
header1: "SQL INSERT Statements"
10+
header2: "MongoDB insert() Statements"
11+
header3: "Reference"
12+
---
13+
# table content, as content.<key>
14+
section: content
15+
sql1: |
16+
17+
.. code-block:: sql
18+
19+
INSERT INTO users(user_id,
20+
age,
21+
status)
22+
VALUES ("bcd001",
23+
45,
24+
"A")
25+
mongo1: |
26+
.. code-block:: javascript
27+
:emphasize-lines: 1-5
28+
29+
db.users.insert( {
30+
user_id: "bcd001",
31+
age: 45,
32+
status: "A"
33+
} )
34+
ref1: |
35+
See :method:`insert() <db.collection.insert()>`
36+
for more information.
37+
...
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# table structure. all content symbolic.
2+
section: layout
3+
header: [ meta.header1, meta.header2, meta.header3]
4+
rows:
5+
- 1: [ content.sql1, content.mongo1, content.ref1 ]
6+
- 2: [ content.sql2, content.mongo2, content.ref2 ]
7+
- 3: [ content.sql3, content.mongo3, content.ref3 ]
8+
- 4: [ content.sql4, content.mongo4, content.ref4 ]
9+
- 5: [ content.sql5, content.mongo5, content.ref4 ]
10+
- 6: [ content.sql6, content.mongo6, content.ref6 ]
11+
---
12+
# table metadata, as meta.<key>
13+
section: meta
14+
header1: "SQL Schema Statements"
15+
header2: "MongoDB Schema Statements"
16+
header3: "Reference"
17+
---
18+
# table content, as content.<key>
19+
section: content
20+
sql1: |
21+
.. code-block:: sql
22+
23+
CREATE TABLE users (
24+
id MEDIUMINT NOT NULL
25+
AUTO_INCREMENT,
26+
user_id Varchar(30),
27+
age Number,
28+
status char(1),
29+
PRIMARY KEY (id)
30+
)
31+
mongo1: |
32+
Implicitly created on first :method:`insert
33+
<db.collection.insert()>` operation. The primary key ``_id`` is
34+
automatically added if ``_id`` field is not specified.
35+
36+
.. code-block:: javascript
37+
:emphasize-lines: 1-5
38+
39+
db.users.insert( {
40+
user_id: "abc123",
41+
age: 55,
42+
status: "A"
43+
} )
44+
45+
However, you can also explicitly create a table:
46+
47+
.. code-block:: javascript
48+
:emphasize-lines: 1
49+
50+
db.createCollection("users")
51+
ref1: |
52+
See
53+
:method:`insert() <db.collection.insert()>` and
54+
:method:`createCollection() <db.createCollection()>`
55+
for more information.
56+
sql2: |
57+
.. code-block:: sql
58+
59+
ALTER TABLE users
60+
ADD join_date DATETIME
61+
mongo2: |
62+
Update operations can add fields to all documents in a
63+
collection:
64+
65+
.. code-block:: javascript
66+
:emphasize-lines: 1-5
67+
68+
db.users.update(
69+
{ },
70+
{ $set: { join_date: null } },
71+
{ multi: 1 }
72+
)
73+
74+
Because each :term:`document` determines its own fields, a
75+
document may contain fields not contained by the other
76+
documents in the collection.
77+
ref2: |
78+
See :method:`update() <db.collection.update()>` and
79+
:operator:`$set` for more information.
80+
sql3: |
81+
.. code-block:: sql
82+
83+
ALTER TABLE users
84+
DROP COLUMN join_date
85+
mongo3: |
86+
Update operations can remove fields from all documents in a
87+
collection:
88+
89+
.. code-block:: javascript
90+
:emphasize-lines: 1-5
91+
92+
db.users.update(
93+
{ },
94+
{ $unset: { join_date: "" } },
95+
{ multi: 1 }
96+
)
97+
ref3: |
98+
See :method:`update() <db.collection.update()>`
99+
and :operator:`$unset` for more information.
100+
sql4: |
101+
.. code-block:: sql
102+
103+
CREATE INDEX idx_user_id_asc
104+
ON users(user_id)
105+
mongo4: |
106+
.. code-block:: javascript
107+
:emphasize-lines: 1
108+
109+
db.users.ensureIndex( { user_id: 1 } )
110+
ref4: |
111+
See :method:`ensureIndex() <db.collection.ensureIndex()>`
112+
and :doc:`indexes </core/indexes>` for more information.
113+
sql5: |
114+
.. code-block:: sql
115+
116+
CREATE INDEX idx_user_id_asc_age_desc
117+
ON users(name, age DESC)
118+
mongo5: |
119+
.. code-block:: javascript
120+
:emphasize-lines: 1
121+
122+
db.users.ensureIndex( { user_id: 1, age: -1 } )
123+
sql6: |
124+
.. code-block:: sql
125+
126+
DROP TABLE users
127+
mongo6: |
128+
.. code-block:: javascript
129+
:emphasize-lines: 1
130+
131+
db.users.remove()
132+
ref6: |
133+
See :method:`remove() <db.collection.remove()>` for
134+
more information.
135+
...

0 commit comments

Comments
 (0)