Question: Question 7 Consider that our posts collection contains an array field called tags that contains tags that the user enters. { _ id: 1 ,

Question 7
Consider that our posts collection contains an array field called tags that contains tags that the user enters.
{_id: 1, tags: ["tutorial", "fun", "learning"], post_text: "This is my first post", topic_category: "lecture"}
What does the following command return?
db.posts.find({ "tags.0": "tutorial" })
All the posts whose tags array contains tutorial
All the posts which contains only one tag element in the tag array
All the posts having the first element of the tags array as tutorial
All the posts which contains 0 or more tags named tutorial
5 points
Question 8
Consider that the posts collection contains an array called ratings which contains ratings given to the post by various users in the following format:
{_id: 1, post_text: "This is my first post", ratings: [5,4,2,5],//other elements of document }
Which query will return all the documents where the array ratings contains at least one element between 3 and 6?
db.inventory.find({ ratings: { $elemMatch: { $gt: 3, $lt: 6}}})
db.inventory.find({ ratings: { ratings: { $gt: 5, $lt: 9}}})
db.inventory.find({ ratings: { ratings.$: { $gt: 5, $lt: 9}}})
db.inventory.find({ ratings: { $elemMatch: { $gte: 3, $lte: 6}}})
5 points
Question 9
Consider that the posts collection contains an array called ratings which contains ratings given to the post by various users in the following format:
{ id: 1, post_text: "This is my first post", ratings: [5,4,2,5],//other elements of document }
Which query will return all the documents where the ratings array contains elements that in some combination satisfy the query conditions?
db.inventory.find({ ratings: { $elemMatch: { $gt: 3, $lt: 6}}})
db.inventory.find({ ratings: { ratings: { $gt: 5, $lt: 9}}})
db.inventory.find({ ratings: { ratings.$: { $gt: 5, $lt: 9}}})
db.inventory.find({ ratings: { $elemMatch: { $gte: 3, $lte: 6}}})
5 points
Question 10
Consider the following posts document:
{ id: 1, post_text: "This is my first post", author: "Tom", tags: ["tutorial","quiz","facebook","learning","fun"]}
Which of the following queries will return the documents but with only the first two tags in the tags array?
db.posts.find({author:"Tom"},{tags:{$slice:2}})
db.posts.find({author:"Tom"}).limit({tags:2})
db.posts.find({author:"Tom"}).limit($slice:{tags:2})
Both a and c are valid. $slice works both with projection and limit.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!