M001: MongoDB Basics Final Exam学习记录

M001: MongoDB Basics Final Exam学习记录

运行环境

操作系统:windows 10 家庭中文版
Mongodb :Mongodb 3.4

Mongodb安装路径:E:>MongoDB\Server\3.4\bin\
Mongodb存储路径:E:>MongoDB\data

课后问题

Final Exam: Question 1

Problem:
Connect to our class Atlas cluster from Compass and view the citybike.trips collection. Use the schema view and any filters you feel are necessary to determine the range of values for the usertype field. Which of the following are values found in this collection for the field usertype?

Check all answers that apply:

  • “Anonymous”
  • “Customer”
  • “Subscriber”
  • null
  • “Pay As You Go”

解答

按要求使用Compass 连接到Atlas集群(方法参见M001: MongoDB Basics chapter 2 The MongoDB Query Language + Atlas学习记录

进入citybike库的trips集合,并进入schema 界面:

这里写图片描述

通过视图可知,usertype 字段95%为”Subscriber”,5%为”Customer”

Final Exam: Question 2

Problem:
Connect to our class Atlas cluster from Compass and view the 100YWeatherSmall.data collection. Using the Schema view, explore the wind field. The wind field has the value type of document. Which of the following best describes the schema of this embedded document?

Choose the best answer:

  • Two fields – one field with the value type “string”, one with a value type of “document”
  • Three fields – two with the value type “document”, one with the value type “string”
  • Two fields – both with the value type “document”
  • Three fields – all with the value type “document”
  • Three fields – two with the value type “string”, one with the value type of “int32”

解答

连接到100YWeatherSmall库的data集合,使用schema视图界面查看wind字段:

这里写图片描述

观察到他含有3个子字段,点开发现有一个string类型,二个document

Final Exam: Question 3

Problem:
Connect to the M001 class Atlas cluster from Compass and view the 100YWeatherSmall.data collection. What is the value type of the “wind.speed.rate” field?

Choose the best answer:

  • array
  • double
  • int32
  • document
  • string

解答

连接到100YWeatherSmall库的data集合,使用schema视图界面查看wind字段的子字段:

这里写图片描述

wind.speed.rate的字段类型为double

Final Exam: Question 4

Problem:

Please connect to the M001 class Atlas cluster. You may answer this question using either the mongo shell or Compass.

For this question we will use the citibike database.

How many documents in the citibike.trips collection have the key tripduration set to null? Ignore any documents that do not contain the tripduration key.

Choose the best answer:

  • 2
  • 3
  • 11
  • 47
  • 114

解答

按要求打开citibike库的trips集合,执行查询:

{$and: [{tripduration: null}, {tripduration: {$exists: true}}]}

相当于mogodb shell中的

db.trips.find({$and: [{tripduration: null}, {tripduration: {$exists: true}}]}).count()

结果为2

Final Exam: Question 5

Problem:

Using the video.movieDetails collection, which of the queries below would produce output documents that resemble the following. Check all that apply.

{ “title” : “P.S. I Love You” }
{ “title” : “Love Actually” }
{ “title” : “Shakespeare in Love” }

NOTE: We are not asking you to consider specifically which documents would be output from the queries below, but rather what fields the output documents would contain.

Check all answers that apply:

  • db.movieDetails.find({}, {title})
  • db.movieDetails.find({title: “Muppets from Space”}, {title: 1})
  • db.movieDetails.find({}, {title: 1, _id: 0})
  • db.movieDetails.find({}, {title: 1})
  • db.movieDetails.find({title: “”}, {title: 1})
  • db.movieDetails.find({year: 1964}, {title: 1, _id: 0})

解答

所求答案只输出title字段,而不输出_id字段,所以必须是{title: 1, _id: 0}收尾

Final Exam: Question 6

Problem:

Please connect to the M001 class Atlas cluster from the mongo shell or Compass and view the video.movies collection. How many movies match the following criteria?

  • The cast includes either of the following actors: “Jack Nicholson”, “John Huston”.
  • The viewerRating is greater than 7.
  • The mpaaRating is “R”.

Choose the best answer:

  • 1
  • 5
  • 8
  • 19
  • 26

解答

按要求进入video库movies集合,查询条件:

  • cast字段为”Jack Nicholson”或”John Huston”
  • viewerRating字段大于7
  • mpaaRating字段为”R”
{$and:[{$or:[{cast:"Jack Nicholson"},{cast: "John Huston"}]},{viewerRating :{$gt:7}},{mpaaRating :"R"}]}

相当于mogodb shell中的

db.movies.find({$and:[{$or:[{cast:"Jack Nicholson"},{cast: "John Huston"}]},{viewerRating :{$gt:7}},{mpaaRating :"R"}]}).count()

这里写图片描述

答案为8

猜你喜欢

转载自blog.csdn.net/sunbocong/article/details/79997430