Skip to content

Commit e0634ca

Browse files
authored
DOCSP-34477 Merge Query Converter Content (#68)
* DOCSP-33454 Query Converter Content (#58) * DOCSP-33454 Query Converter Content * DOCSP-32086 Convert Stored Procedures Content (#64) * DOCSP-32086 Convert Stored Procedures Content * DOCSP-33246 Convert Views Content (#63) * DOCSP-33246 Convert Views Content * DOCSP-33003 Refresh Database Objects (#65) * remove empty file
1 parent 64d4b5d commit e0634ca

11 files changed

+924
-3
lines changed

.github/pull_request_template.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## DESCRIPTION
2+
3+
4+
## STAGING
5+
6+
7+
## JIRA
8+
9+
10+
## BUILD LOG
11+
12+
13+
## Self-Review Checklist
14+
15+
- [ ] Is this free of any warnings or errors in the RST?
16+
- [ ] Is this free of spelling errors?
17+
- [ ] Is this free of grammatical errors?
18+
- [ ] Is this free of staging / rendering issues?
19+
- [ ] Are all the links working?
20+
21+
## External Review Requirements
22+
23+
[What's expected of an external reviewer?](https://wiki.corp.mongodb.com/display/DE/Reviewing+Guidelines+for+the+MongoDB+Server+Documentation)

snooty.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name = "docs-relational-migrator"
22
title = "Relational Migrator"
33

44
intersphinx = [ "https://www.mongodb.com/docs/manual/objects.inv",
5-
"https://www.mongodb.com/docs/atlas/objects.inv"
5+
"https://www.mongodb.com/docs/atlas/objects.inv",
6+
"https://www.mongodb.com/docs/atlas/app-services/objects.inv"
67
]
7-
8+
89
# toc_landing_pages = ["/paths/to/pages/that/have/nested/content"]
910

1011
toc_landing_pages = [
@@ -30,7 +31,8 @@ toc_landing_pages = [
3031
"jobs/data-verification/data-verification",
3132
"connection-strings/connection-strings",
3233
"code-generation",
33-
"code-generation/generate-app-code"
34+
"code-generation/generate-app-code",
35+
"code-generation/query-converter"
3436
]
3537

3638
[constants]

source/code-generation/query-converter.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,13 @@ preview. To request private preview access, use the sign-up form within the
2323
Relational Migrator application:
2424

2525
.. include:: /includes/fact-request-private-preview.rst
26+
27+
.. toctree::
28+
:hidden:
29+
:titlesonly:
30+
31+
/code-generation/query-converter/enable-query-converter
32+
/code-generation/query-converter/convert-queries
33+
/code-generation/query-converter/convert-stored-procedures
34+
/code-generation/query-converter/convert-views
35+
/code-generation/query-converter/refresh-database-objects
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
.. _rm-convert-queries:
2+
3+
===============
4+
Convert Queries
5+
===============
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
You can convert embedded application and reporting SQL queries to MongoDB
14+
syntax using the query converter. Copy and paste your queries into the
15+
query converter to update them to work with MongoDB and your migrated
16+
schema.
17+
18+
About this Task
19+
---------------
20+
21+
.. include:: /includes/fact-query-converter-generic.rst
22+
23+
- .. include:: /includes/fact-query-converter-disclaimer.rst
24+
25+
Steps
26+
-----
27+
28+
.. procedure::
29+
:style: normal
30+
31+
.. step:: Navigate to the query converter pane
32+
33+
From the :guilabel:`Code Generation` tab, click the
34+
:guilabel:`Query Converter` pane.
35+
36+
.. step:: Open the SQL query converter view
37+
38+
- If it is your first time using the query converter in your
39+
project, click :guilabel:`Paste SQL Query`.
40+
- If you have previously converted SQL code in your project, click the
41+
:guilabel:`+ ADD` button on the left-hand pane next to
42+
:guilabel:`Queries`.
43+
44+
.. step:: Enter your SQL query
45+
46+
a. Copy your SQL query to your clipboard.
47+
48+
.. note::
49+
50+
Queries copied into the :guilabel:`SQL Query` text field
51+
must be a SELECT query. For example:
52+
``SELECT ID,ITEMNAME,PRICE FROM inventory``.
53+
54+
#. Under the :guilabel:`SQL Query` header, paste your SQL query
55+
into the text box.
56+
57+
.. step:: Convert and test syntax
58+
59+
a. Click the :guilabel:`Convert` button. Wait for your SQL code to
60+
converted. The converted MongoDB syntax code displays
61+
in the :guilabel:`Converted MongoDB Query` text box.
62+
63+
.. tip::
64+
65+
You can rename or delete queries from your project
66+
by clicking the :icon-fa4:`ellipsis-h`
67+
button on the :guilabel:`SQL Query` pane and clicking the
68+
:icon-fa5:`pencil-alt` or :icon-fa4:`trash` icon.
69+
70+
#. Click the :icon-fa5:`copy` icon to copy the MongoDB syntax
71+
to your clipboard.
72+
#. Test and validate the generated MongoDB syntax.
73+
74+
.. tip::
75+
76+
.. include:: /includes/fact-query-converter-filter.rst
77+
78+
Examples
79+
--------
80+
81+
The following table shows examples of SQL queries converted to MongoDB
82+
syntax using query converter. The syntax and structure of the converted
83+
queries vary depending on the mapping rules used in the project:
84+
85+
.. list-table::
86+
:header-rows: 1
87+
:widths: 40 60
88+
89+
* - SQL Syntax
90+
- MongoDB Syntax
91+
92+
* -
93+
.. code-block:: sql
94+
:copyable: false
95+
96+
SELECT *
97+
FROM CUSTOMERS
98+
-
99+
.. code-block::
100+
:copyable: false
101+
102+
async function query(db) {
103+
return await db.collection('Customers').find({
104+
}).toArray();
105+
}
106+
107+
* -
108+
.. code-block:: sql
109+
:copyable: false
110+
111+
SELECT CONTACTNAME, CITY
112+
FROM CUSTOMERS
113+
WHERE CONTACTNAME LIKE '%SMITH%'
114+
115+
-
116+
.. code-block:: node
117+
:copyable: false
118+
119+
async function query(db) {
120+
return await db.collection('Customers').find({
121+
ContactName: { $regex: '.*SMITH.*' }
122+
}, {
123+
projection: { ContactName: 1, City: 1, _id: 0 }
124+
}).toArray();
125+
}
126+
127+
* -
128+
.. code-block:: sql
129+
:copyable: false
130+
131+
SELECT CUSTOMERID, CITY
132+
FROM CUSTOMERS AS C
133+
JOIN ORDERS AS O
134+
ON C.CUSTOMERID = O.CUSTOMERID
135+
WHERE CONTACTNAME IN('ABI','JIM')
136+
137+
-
138+
.. code-block:: node
139+
:copyable: false
140+
141+
const query = async (db) => {
142+
return await db.collection('Customers').aggregate([
143+
{
144+
$lookup: {
145+
from: 'Orders',
146+
localField: 'CustomerId',
147+
foreignField: 'CustomerId',
148+
as: 'customer_orders'
149+
}
150+
},
151+
{
152+
$match: {
153+
CONTACTNAME: { $in: ['ABI', 'JIM'] }
154+
}
155+
},
156+
{
157+
$project: {
158+
CustomerId: 1,
159+
City: 1
160+
}
161+
}
162+
]).toArray();
163+
};
164+
165+
Next Steps
166+
----------
167+
168+
- :ref:`rm-convert-views`
169+
- :ref:`rm-convert-stored-procedures`
170+
171+
Learn More
172+
----------
173+
174+
- :ref:`sql-to-mongodb-mapping`
175+
- :manual:`SQL to Aggregation Mapping Chart </reference/sql-aggregation-comparison>`

0 commit comments

Comments
 (0)