Mongodb Certified Developer Associate C100dev · Free Practice Question Medium
Question 12
The following capped collection is given:
- db.createCollection('latest_news', {'capped': true, 'size': 10000, 'max': 3})
- [
- {
- _id: ObjectId("61e8007c9b3067e362440a88"),
- title: 'COVID records broken again as weekend brings nearly 40K new cases'
- },
- {
- _id: ObjectId("61e800989b3067e362440a89"),
- title: 'Bitcoin, Ethereum, Dogecoin Face Fresh Round Of Regulatory Scrutiny'
- },
- {
- _id: ObjectId("61e800d19b3067e362440a8a"),
- title: 'Where Six Meme Stock Investors Are Now'
- }
- ]
What the latest_news collection will look like after the following operation?
- db.latest_news.insertOne({
- title: "TikTok owner ByteDance dissolves its investment arm"
- })
-
A
- [
- {
- _id: ObjectId("61e8007c9b3067e362440a88"),
- title: 'COVID records broken again as weekend brings nearly 40K new cases'
- },
- {
- _id: ObjectId("61e800989b3067e362440a89"),
- title: 'Bitcoin, Ethereum, Dogecoin Face Fresh Round Of Regulatory Scrutiny'
- },
- {
- _id: ObjectId("61e800d19b3067e362440a8a"),
- title: 'Where Six Meme Stock Investors Are Now'
- }
- ]
-
B
- [
- {
- _id: ObjectId("61e8007c9b3067e362440a88"),
- title: 'COVID records broken again as weekend brings nearly 40K new cases'
- },
- {
- _id: ObjectId("61e800989b3067e362440a89"),
- title: 'Bitcoin, Ethereum, Dogecoin Face Fresh Round Of Regulatory Scrutiny'
- },
- {
- _id: ObjectId("61e800d19b3067e362440a8a"),
- title: 'Where Six Meme Stock Investors Are Now'
- },
- {
- _id: ObjectId("61e801439b3067e362440a8b"),
- title: 'TikTok owner ByteDance dissolves its investment arm'
- }
- ]
-
C
- [
- {
- _id: ObjectId("61e801439b3067e362440a8b"),
- title: 'TikTok owner ByteDance dissolves its investment arm'
- }
- ]
-
D
- [
- {
- _id: ObjectId("61e800989b3067e362440a89"),
- title: 'Bitcoin, Ethereum, Dogecoin Face Fresh Round Of Regulatory Scrutiny'
- },
- {
- _id: ObjectId("61e800d19b3067e362440a8a"),
- title: 'Where Six Meme Stock Investors Are Now'
- },
- {
- _id: ObjectId("61e801439b3067e362440a8b"),
- title: 'TikTok owner ByteDance dissolves its investment arm'
- }
- ]
Reveal correct answer
Correct answer: D
A.
This option represents the initial state of the collection before executing the insertOne operation. It does not include the newly inserted document and, therefore, is not the correct answer.
B.
This option includes the initial documents of the collection but does not consider the new document that is being inserted. It does not reflect the outcome of the insertOne operation and, therefore, is not the correct answer.
C.
This option only includes the newly inserted document with the title "TikTok owner ByteDance dissolves its investment arm." However, it fails to consider the capped nature of the collection, which allows a maximum of 3 documents. As per the capped collection settings, the collection should still contain the three most recent documents.
D.
This option represents the correct result after executing the operation db.latest_news.insertOne({...}). The new document with the title "TikTok owner ByteDance dissolves its investment arm" will be added to the capped collection, and as the collection has a maximum size of 10,000 bytes and a maximum of 3 documents, the oldest document (COVID records) will be removed to make room for the new document. Therefore, the resulting collection will include the three most recent documents, with the "COVID records" document being replaced by the "TikTok owner ByteDance dissolves its investment arm" document.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
