M001: MongoDB Basics Chapter 3: Deeper Dive on the MongoDB Query Language学习记录

M001: MongoDB Basics Chapter 3: Deeper Dive on the MongoDB Query Language学习记录

运行环境

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

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

课后问题

Comparison Operators(比较运算符)

Problem:
Using the $in operator, filter the video.movieDetails collection to determine how many movies list either “Ethan Coen” or “Joel Coen” among their writers. Your filter should match all movies that list either of the Coen brothers as writers regardless of how many other writers are also listed. Select the number of movies matching this filter from the choices below.

Check all answers that apply:

Attempts Remaining:Correct Answer

  • 0
  • 3
  • 7
  • 12
  • 16

解答

In the mongo shell, assuming you’ve loaded movieDetails into the video database and assuming you are connected to your Atlas sandbox cluster, you can issue the following commands.

use video

db.movieDetails.find({writers: {$in: ["Ethan Coen", "Joel Coen"]}}).count()

In Compass, navigate to the video.movieDetails collection in your Atlas sandbox cluster. Then apply the following filter in either the Schema view or Documents view.

{
   writers: {$in: ["Ethan Coen", "Joel Coen"]}}

答案为3

相关示例

runtime大于90:

db.movieDetails.find({
   runtime: {$gt: 90}})

runtime大于90,指定返回title,runtime字段:

db.movieDetails.find({
   runtime: {$gt: 90}}, {
   _id: 0, title: 1, runtime: 1})

runtime大于90小于120,指定返回title,runtime字段:

db.movieDetails.find({
   runtime: {$gt: 90, $lt: 120}}, {
   _id: 0, title: 1, runtime: 1})

runtime大于等于90小于等于120,指定返回title,runtime字段:

db.movieDetails.find({
   runtime: {$gte: 90, $lte: 120}}, {
   _id: 0, title: 1, runtime: 1})

runtime大于等于180且tomato.meter为100,指定返回title,runtime字段:

db.movieDetails.find({
   runtime: {$gte: 180}, "tomato.meter": 100}, {
   _id: 0, title: 1, runtime: 1})

rated不等于UNRATED,指定返回title,rated字段:

db.movieDetails.find({
   rated: {$ne: "UNRATED"}}, {
   _id: 0, title: 1, rated: 1})

rated为G或者PG,指定返回title,rated字段:

db.movieDetails.find({
   rated: {$in: ["G", "PG"]}}, {
   _id: 0, title: 1, rated: 1})

rated为G或者PG或者PG-13,指定返回title,rated字段,用pretty格式:

db
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值