- Web Development with MongoDB and Node(Third Edition)
- Bruno Joseph D'mello Mithun Satheesh Jason Krol
- 244字
- 2021-07-08 10:32:43
Checking the actual database
Let's take a quick look at the database itself to see what happened during the execution of the app. Since the server is currently up and running, we can connect to it using the Mongo shell-a command line interface to the MongoDB server. Execute the following commands to connect to the server using Mongo and run a query against the chapter's collection. As you can see in the upcoming code, Mongo shell connects to a default database named test initially. We need to manually specify the database name to switch to if it's something other than test:
$ mongo MongoDB shell version: 2.4.8 connecting to: test > use myproject > show collections chapters system.indexes > db.chapters.find().pretty()
Here, pretty is used as part of the command to format the result from the find command. This is used only in a shell context. It does more of a prettification task for the JSON.
You should see something similar to the following output:
{ 'id' : ObjectId("5547e734cdf16a5ca59531a7"), 'Title': 'Snow Crash', 'Author': 'Neal Stephenson' }, { 'id' : ObjectId("5547e734cdf16a5ca59531a7"), 'Title': 'Snow Crash', 'Author': 'Neal Stephenson' }
If you run the Node app again, the records will be inserted into the Mongo server again. So, if you repeat the command multiple times, the result will have more records in the output. We are not handling this case in this chapter as we intend to have only specific code, that will be simple enough to understand.
推薦閱讀
- Java程序設計實戰教程
- 程序設計與實踐(VB.NET)
- 從程序員到架構師:大數據量、緩存、高并發、微服務、多團隊協同等核心場景實戰
- Python測試開發入門與實踐
- 零基礎學Java(第4版)
- Elasticsearch for Hadoop
- Learning Hunk
- 低代碼平臺開發實踐:基于React
- Test-Driven Machine Learning
- Building Machine Learning Systems with Python(Second Edition)
- Android嵌入式系統程序開發:基于Cortex-A8(第2版)
- 實戰Java高并發程序設計(第2版)
- Photoshop CC移動UI設計案例教程(全彩慕課版·第2版)
- MongoDB Administrator’s Guide
- Python Penetration Testing Essentials