Getting Started with MongoDB and AWS Codewhisperer
# Getting Started with MongoDB and AWS Codewhisperer

**Introduction**
----------------

Amazon CodeWhisperer is trained on billions of lines of code and can generate code suggestions — ranging from snippets to full functions — in real-time, based on your comments and existing code. AI code assistants have revolutionized developers’ coding experience, but what sets Amazon CodeWhisperer apart is that MongoDB has collaborated with the AWS Data Science team, enhancing its capabilities!

At MongoDB, we are always looking to enhance the developer experience, and we've fine-tuned the CodeWhisperer Foundational Models to deliver top-notch code suggestions — trained on, and tailored for, MongoDB. This gives developers of all levels the best possible experience when using CodeWhisperer for MongoDB functions.
This tutorial will help you get CodeWhisperer up and running in VS Code, but CodeWhisperer also works with a number of other IDEs, including IntelliJ IDEA, AWS Cloud9, AWS Lambda console, JupyterLab, and Amazon SageMaker Studio. On the [Amazon CodeWhisperer site][1], you can find tutorials that demonstrate how to set up CodeWhisperer on different IDEs, as well as other documentation.

*Note:* CodeWhisperer allows users to start without an AWS account because usually, creating an AWS account requires a credit card. Currently, CodeWhisperer is free for individual users. So it’s super easy to get up and running.

**Installing CodeWhisperer for VS Code** 

CodeWhisperer doesn’t have its own VS Code extension. It is part of a larger extension for AWS services called AWS Toolkit. AWS Toolkit is available in the VS Code extensions store.
1. Open VS Code and navigate to the extensions store (bottom icon on the left panel).
 2. Search for CodeWhisperer and it will show up as part of the AWS Toolkit.
![Searching for the AWS ToolKit Extension][2]
 3. Once found, hit Install. Next, you’ll see the full AWS Toolkit
    Listing
![The AWS Toolkit full listing][3]
 4. Once installed, you’ll need to authorize CodeWhisperer via a Builder
    ID to connect to your AWS developer account (or set up a new account
    if you don’t already have one).
![Authorise CodeWhisperer][4]

**Using CodeWhisperer**
-----------------------

Navigating code suggestions 

![CodeWhisperer Running][5]
**Using CodeWhisperer**
-----------------------

Navigating code suggestions 

![CodeWhisperer Running][5]

With CodeWhisperer installed and running, as you enter your prompt or code, CodeWhisperer will offer inline code suggestions. If you want to keep the suggestion, use **TAB** to accept it. CodeWhisperer may provide multiple suggestions to choose from depending on your use case. To navigate between suggestions, use the left and right arrow keys to view them, and **TAB** to accept.

If you don’t like the suggestions you see, keep typing (or hit **ESC**). The suggestions will disappear, and CodeWhisperer will generate new ones at a later point based on the additional context.

**Requesting suggestions manually**
**Requesting suggestions manually**

You can request suggestions at any time. Use **Option-C** on Mac or **ALT-C** on Windows. After you receive suggestions, use **TAB** to accept and arrow keys to navigate.

**Getting the best recommendations**

For best results, follow these practices.
**Getting the best recommendations**

For best results, follow these practices.

 - Give CodeWhisperer something to work with. The more code your file contains, the more context CodeWhisperer has for generating recommendations.
 - Write descriptive comments in natural language — for example
```
// Take a JSON document as a String and store it in MongoDB returning the _id
```
Or
```
//Insert a document in a collection with a given _id and a discountLevel
```
 - Specify the libraries you prefer at the start of your file by using import statements.
```
// This Java class works with MongoDB sync driver.
// This class implements Connection to MongoDB and CRUD methods.
```
 - Use descriptive names for variables and functions
 - Break down complex tasks into simpler tasks

**Provide feedback**
----------------
**Provide feedback**
----------------

As with all generative AI tools, they are forever learning and forever expanding their foundational knowledge base, and MongoDB is looking for feedback. If you are using Amazon CodeWhisperer in your MongoDB development, we’d love to hear from you. 

We’ve created a special “codewhisperer” tag on our [Developer Forums][6], and if you tag any post with this, it will be visible to our CodeWhisperer project team and we will get right on it to help and provide feedback. If you want to see what others are doing with CodeWhisperer on our forums, the [tag search link][7] will jump you straight into all the action. 

We can’t wait to see your thoughts and impressions of MongoDB and Amazon CodeWhisperer together.
[1]: https://aws.amazon.com/codewhisperer/resources/#Getting_started
  [2]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt1bfd28a846063ae9/65481ef6e965d6040a3dcc37/CW_1.png
  [3]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltde40d5ae1b9dd8dd/65481ef615630d040a4b2588/CW_2.png
  [4]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt636bb8d307bebcee/65481ef6a6e009040a740b86/CW_3.png
[5]: https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltf1e0ebeea2089e6a/65481ef6077aca040a5349da/CW_4.png
  [6]: https://www.mongodb.com/community/forums/
  [7]: https://www.mongodb.com/community/forums/tag/codewhisperer