Skip to content

Commit 5a6f586

Browse files
committed
Updated Mongo export code sample
1 parent b37a38e commit 5a6f586

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

articles/cosmos-db/mongodb/tutorial-mongotools-cosmos-db.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ The rest of this section will guide you through using the pair of tools you sele
102102

103103
1. To export the data from the source MongoDB instance, open a terminal on the MongoDB instance machine. If it is a Linux machine, type
104104

105-
`mongoexport --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection query --out edx.json`
105+
```bash
106+
mongoexport --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection query --out edx.json
107+
```
106108

107109
On windows, the executable will be `mongoexport.exe`. *HOST*, *PORT*, *USERNAME*, and *PASSWORD* should be filled in based on the properties of your existing MongoDB database instance.
108110

109111
You may also choose to export only a subset of the MongoDB dataset. One way to do this is by adding an additional filter argument:
110112

111-
`mongoexport --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection query --out edx.json --query '{"field1":"value1"}'`
113+
```bash
114+
mongoexport --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection query --out edx.json --query '{"field1":"value1"}'
115+
```
112116

113117
Only documents which match the filter `{"field1":"value1"}` will be exported.
114118

@@ -117,7 +121,9 @@ The rest of this section will guide you through using the pair of tools you sele
117121
![Screenshot of mongoexport call.](media/tutorial-mongotools-cosmos-db/mongo-export-output.png)
118122
1. You can use the same terminal to import `edx.json` into Azure Cosmos DB. If you are running `mongoimport` on a Linux machine, type
119123

120-
`mongoimport --host HOST:PORT -u USERNAME -p PASSWORD --db edx --collection importedQuery --ssl --type json --writeConcern="{w:0}" --file edx.json`
124+
```bash
125+
mongoimport --host HOST:PORT -u USERNAME -p PASSWORD --db edx --collection importedQuery --ssl --type json --writeConcern="{w:0}" --file edx.json
126+
```
121127

122128
On Windows, the executable will be `mongoimport.exe`. *HOST*, *PORT*, *USERNAME*, and *PASSWORD* should be filled in based on the Azure Cosmos DB credentials you collected earlier.
123129
1. **Monitor** the terminal output from *mongoimport*. You should see that it prints lines of text to the terminal containing updates on the migration status:
@@ -132,14 +138,18 @@ The rest of this section will guide you through using the pair of tools you sele
132138

133139
1. To create a BSON data dump of your MongoDB instance, open a terminal on the MongoDB instance machine. If it is a Linux machine, type
134140

135-
`mongodump --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection query --out edx-dump`
141+
```bash
142+
mongodump --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection query --out edx-dump
143+
```
136144

137145
*HOST*, *PORT*, *USERNAME*, and *PASSWORD* should be filled in based on the properties of your existing MongoDB database instance. You should see that an `edx-dump` directory is produced and that the directory structure of `edx-dump` reproduces the resource hierarchy (database and collection structure) of your source MongoDB instance. Each collection is represented by a BSON file:
138146

139147
![Screenshot of mongodump call.](media/tutorial-mongotools-cosmos-db/mongo-dump-output.png)
140148
1. You can use the same terminal to restore the contents of `edx-dump` into Azure Cosmos DB. If you are running `mongorestore` on a Linux machine, type
141149

142-
`mongorestore --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection importedQuery --ssl edx-dump/edx/query.bson`
150+
```bash
151+
mongorestore --host HOST:PORT --authenticationDatabase admin -u USERNAME -p PASSWORD --db edx --collection importedQuery --writeConcern="{w:0}" --ssl edx-dump/edx/query.bson
152+
```
143153

144154
On Windows, the executable will be `mongorestore.exe`. *HOST*, *PORT*, *USERNAME*, and *PASSWORD* should be filled in based on the Azure Cosmos DB credentials you collected earlier.
145155
1. **Monitor** the terminal output from *mongorestore*. You should see that it prints lines to the terminal updating on the migration status:

0 commit comments

Comments
 (0)