官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 新建县| 乌鲁木齐县| 阳山县| 博兴县| 浦县| 钦州市| 凤凰县| 佛坪县| 思茅市| 潢川县| 遂昌县| 崇州市| 大丰市| 营口市| 仁化县| 裕民县| 巴林右旗| 陕西省| 丰宁| 北宁市| 神农架林区| 敖汉旗| 义乌市| 赤壁市| 晋宁县| 崇文区| 西盟| 姚安县| 璧山县| 锦屏县| 彭山县| 望城县| 灯塔市| 晋城| 恭城| 剑河县| 南康市| 天祝| 驻马店市| 巴林右旗| 德格县|