Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

Export Query to Specific Language

You can export queries created in the query bar to one of the supported languages; Java, Node, C#, Python 3, Ruby, Go, Rust, and PHP. This feature allows you to reformat and use Atlas queries in your application.

1
  1. If it's not already displayed, select the organization that contains your project from the Organizations menu in the navigation bar.

  2. If it's not already displayed, select your project from the Projects menu in the navigation bar.

  3. In the sidebar, click Data Explorer under the Database heading.

    The Data Explorer displays.

IMPORTANT: You can also click the name of a cluster to open the Cluster sidebar, and then click Data Explorer under the Shortcuts heading.

2
  1. Select the collection.

  2. In the query bar, click the Export Code icon to open the query export card.

Query bar export dropdown menu
3

On the right side of the card, click the drop-down menu under Exported Query and select your desired programming language.

The My Query pane on the left of the export card displays your pipeline in mongosh syntax. The Exported Query pane to the right displays your pipeline in the selected programming language.

Query bar language select
4

Click the Include Import Statements checkbox to include the required import statements for the selected programming language.

5

Click the Include Driver Syntax checkbox to include application code for the selected programming language. If you include driver syntax, the copyable code reflects project, sort, maxtimems, collation, skip, and limit options.

6

Click the icon at the top-right corner of the formatted query to copy the query for the selected language to your clipboard. You can now integrate and execute your created query in your application.

Copy button clicked in Export Query to Language modal