Navicat Blog

Aug 21, 2018 by Robert Gravelle

MongoDB is a NoSQL database that stores data as collections of documents. Therefore, it behooves you to learn how to work with both documents and collections. In the MongoDB Documents Tutorial we learned how documents are stored in MongoDB as well as how to append new ones to a collection using the Navicat for MongoDB database administration tool. In today's blog, we'll be covering how to view, delete, and edit documents.

One Document: 3 Views

In Navicat for MongoDB, data can be presented in one of three ways, depending on what you're trying to do with the documents. They are:

  • Grid view

  • Tree view

  • JSON view

If you look at the lower-right quadrant of the Collection Tab, you'll see the three buttons for each view:

They are also accessible via the View command from the Main Menu:

Grid View (pictured above) is the traditional tabular display that DBAs are most familiar with. It can handle any documents size, and supports advanced features like highlighting cells based on data types, column hiding and more.

Tree View shows your documents in a hierarchical view. All embedded documents and arrays are represented as nodes, which can be expanded or collapsed as needed:

You can also show your data as JSON documents, while documents can be added with the built-in validation mechanism which ensures your edits are correct.

Adding and Deleting Documents in Grid View

The previous section described the three View buttons in the lower-right quadrant of the Collection Tab. Now, we'll turn our attention to the lower-left quadrant of the Collection Tab. There, you'll find the Add Document and Delete Document buttons:

Clicking the Add Document button appends an empty row to the end of the grid. You can enter values directly into each cell. The TAB key moves the cursor to the adjacent cell on the right, while SHIFT+TAB moves it one cell to the left.

Clicking the Apply Changes button saves the new document.

Meanwhile, clicking the Discard Changes button removes the new document without saving it to the database.

You can edit an existing document via the Edit Document... command on the context menu:

That brings up the selected document in JSON format for in-place editing:

You can validate the document at any time by clicking the Validate button. Either way, clicking the Update button will validate the document automatically before committing your changes.

Adding and Deleting Documents in Tree View

Clicking the Add Document button in Tree View causes an empty document to open in the editor. Clicking to the right of a field label displays a textbox to enter the value:

Deleting a document in Tree View removes the current document from the database and displays the previous one in the collection.

Adding and Deleting Documents in JSON View

Clicking the Add Document button in JSON View causes the Add Document dialog to appear with an empty document. There, you can enter all of the document fields as free-form text:

Clicking the Delete Document button in JSON View removes the enclosing document around the cursor. A prompt will appear to ask you to confirm the identity of the document.

Going Forward

In upcoming blogs, we'll learn about collection sorting, working with different field types, and filtering documents based on multiple criteria.

Navicat Blogs
Feed Entries
Blog Archives
Share