cert quiz Flashcards
- Which numeric type is a valid MongoDB BSON type?a. Float
b. Number
c. BIGINT
d. 32-bit integer
Your Answer: Correct
d
- Given the following documents in a collection:
{ _id: 1, n: [1,2,5], p: 0.75, c: ‘Green’ },
{ _id: 2, n: ‘Orange’, p: ‘Blue’, c: 42, q: 14 },
{ _id: 3, n: [1,3,7], p: 0.85, c: ‘Orange’ }
Which two documents can successfully be added in the same collection?
b d
- Given the following documents in a collection:
{_id: 1, txt: “just some text”},
{_id: 2, txt: “just some text”}
Which two documents can successfully be added in the same collection?
a. {_id: 0, txt: “just some text”}
b. {_id: 1, txt: “just some text”}
c. {_id: [4], txt: “just some text”}
d. {_id: 3, txt: “just some text”}
a d
- Given the following document:
The name is a.log, the owner of the file is applicationA, the size of the file is 1KB, and the file was deleted.
What command will properly add this document to the files collection using mongosh?
a. db.files.insertOne({ file: “a.log”, owner: “applicationA”, size: 1KB, deleted: true })
b. db.files.insertOne({ file: “a.log”, owner: “applicationA”, size: 1KB, deleted: True })
c. db.files.insertOne({ file: “a.log”, owner: “applicationA”, size: 1024, deleted: true })
d. db.files.insertOne({ file: “a.log”, owner: “applicationA”, size: 1024, deleted: True })
c
- Given the following sample documents in products collection:
{ “name” : “XPhone”, “price” : 799, “color” : [ “white”, “black” ], “storage” : [ 64, 128, 256 ] },
{ “name” : “XPad”, “price” : 899, “color” : [ “white”, “black”, “purple” ], “storage” : [ 128, 256, 512 ] },
{ “name” : “GTablet”, “price” : 899, “color” : [ “blue” ], “storage” : [ 16, 64, 128 ] },
{ “name” : “GPad”, “price” : 699, “color” : [ “white”, “orange”, “gold”, “gray” ], “storage” : [ 128, 256, 1024 ] },
{ “name” : “GPhone”, “price” : 599, “color” : [ “white”, “orange”, “gold”, “gray” ], “storage” : [ 128, 256, 512 ] }
Given the following query:
db.products.find({$and : [{“price” : {$lte : 800}},
{$or : [{“color” : “purple”}, {“storage” : 1024}]}]})
What is the correct output of the query?
(Choose 1)
a. { "name" : "XPhone", "price" : 799, "color" : [ "white", "black" ], "storage" : [ 64, 128, 256 ] } b. { "name" : "XPad", "price" : 899, "color" : [ "white", "black", "purple" ], "storage" : [ 128, 256, 512 ] } c. { "name" : "GPhone", "price" : 599, "color" : [ "white", "orange", "gold", "gray" ], "storage" : [ 128, 256, 512 ] } d. { "name" : "GPad", "price" : 699, "color" : [ "white", "orange", "gold", "gray" ], "storage" : [ 128, 256, 1024 ] }
d
- An
inventory
collection consists of 200 documents.
What method should be used to get all documents from a cursor using mongosh?
(Choose 1)
a. db.inventory.findOne() b. db.inventory.find().toArray(); c. db.inventory.find(); d. db.inventory.findMany().toArray()
b
- A collection has documents like the following:
{ _id: 1, name: ‘Oatmeal Fruit Cake with Gummy Bears ‘, price: 11)},
{ _id: 2, name: ‘Cheesecake Trifle with Chocolate Sprinkles ‘, price: 14)},
{ _id: 3, name: ‘Pistachio Brownie with Walnuts ‘, price: 5},
{ _id: 4, name: ‘Strawberry Ice Cream Cake with Butterscotch Syrup ‘, price: 3)}
How should the ‘autocomplete’ index be defined to look for matches at the beginning of a word on the name field?
(Choose 1)
a. { "mappings": { "dynamic": false, "fields": { "name": [ { "type": "autocomplete", "tokenization": "regexCaptureGroup"} ] } }} b. { "mappings": { "dynamic": false, "fields": { "name": [ { "type": "autocomplete", "tokenization": "edgeGram"} ] } }} c. { "mappings": { "dynamic": false, "fields": { "name": [ { "type": "autocomplete", "tokenization": "nGram"} ] } }} d. { "mappings": { "dynamic": false, "fields": { "name": [ { "type": "autocomplete", "tokenization": "matchNGram"}} ] } }}
b
- Given the following sample documents:
{_id:1, name: “Quesedillas Inc.”, active: true },
{_id:2, name: “Pasta Inc.”, active: true },
{_id:3, name: “Tacos Inc.”, active: false },
{_id:4, name: “Cubanos Inc.”, active: false },
{_id:5, name: “Chicken Parm Inc.”, active: false }
A company wants to create a mobile app for users to find restaurants by name. The developer wants to show the user restaurants that match their search. An Atlas Search index has already been created to support this query.
What query satisfies these requirements?
(Choose 1)
a. db.restaurants.aggregate([{ "$search": { "text": { "path": "name", "synonym": "cuban"} } }]) b. db.restaurants.aggregate([{ "$search": { "text": { "path": "name", "query": "cuban"} } }]) c. db.restaurants.aggregate([{ "$search": { "text": { "field": "name", "query": "cuban"} } }]) d. db.restaurants.aggregate([{ "$search": { "text": { "field": "name", "synonym": "cuban"} } }])
b
- Given the data set and query:
{ “_id” : ObjectId(“512bc95fe835e68f199c8686”), “player” : “p1”, “score” : 89 }
{ “_id” : ObjectId(“512bc962e835e68f199c8687”), “player” : “p2”, “score” : 85 }
{ “_id” : ObjectId(“55f5a192d4bede9ac365b257”), “player” : “p2”, “score” : 65 }
{ “_id” : ObjectId(“55f5a192d4bede9ac365b258”), “player” : “p3”, “score” : 65 }
{ “_id” : ObjectId(“55f5a1d3d4bede9ac365b259”), “player” : “p3”, “score” : 75 }
{ “_id” : ObjectId(“55f5a1d3d4bede9ac365b25a”), “player” : “p5”, “score” : 70 }
{ “_id” : ObjectId(“55f5a1d3d4bede9ac365b25b”), “player” : “p6”, “score” : 100 }
db.scores.aggregate(
[{ $group: {
_id: ‘$player’,
score: {
$avg: ‘$score’
}
},
{ $match: {
score: {
$gt: 70
}
}
])
What is the output?
(Choose 1)
a. { "player" : "p1", "score" : 89 } { "player" : "p2", "score" : 85 } { "player" : "p3", "score" : 75 } { "player" : "p6", "score" : 100 } b. { "player" : "p1", "score" : 89 } { "player" : "p2", "score" : 75 } { "player" : "p6", "score" : 100 } c. { "player" : "p1", "score" : 89 } { "player" : "p2", "score" : 75 } { "player" : "p3", "score" : 70 } { "player" : "p5", "score" : 70 } { "player" : "p6", "score" : 100 } d. { "player" : "p1", "score" : 89 } { "player" : "p2", "score" : 75 } { "player" : "p3", "score" : 70 } { "player" : "p6", "score" : 100 }
b
- A collection coll in database mdb has the following documents :
{_id: 1, type: “A”, value: 60}
{_id: 2, type: “B”, value: 80}
{_id: 3, type: “C”, value: 10}
After executing the following aggregation pipeline:
db.getSiblingDB(“mdb”).coll.aggregate([
{ $out: {db:’test’, collection:’results’}} ])
What are two expected results?
(Choose 2)
a. Collection `results` is created in database `test`. b. There is a syntax error command. Collection `results` is not created. c. No documents in collection `coll` are written to collection `results`. d. All documents in collection `coll` are written to collection `results`.
b c
- Given the following documents:
{_id:1, a: “one”, b: “four”}
{_id:2, a: “two”, b: “four”}
{_id:3, a: “three”, b: “four”, c: “three”}
If the following command is executed:
db.coll.replaceOne({}, {a: “ten”, b: “five”})
What is the result?
(Choose 1)
a. {_id:1, a: "ten", b: "five"} {_id:2, a: "ten", b: "five"} {_id:3, a: "ten", b: "five"} b. {_id:1, a: "ten", b: "five"} {_id:2, a: "two", b: "four"} {_id:3, a: "three", b: "four", c: "three"} c. {_id:1, a: "ten", b: "five"} {_id:2, a: "ten", b: "five"} {_id:3, a: "ten", b: "five", c: "three"} d. {_id:1, a: "one", b: "four"} {_id:2, a: "two", b: "four"} {_id:3, a: "three", b: "four", c: "three"}
b
- Given the collection called coll, with only the following documents,
{
_id:1,
a:1,
b:1
},
{
_id:2,
a:2
}
The update operation db.coll.updateMany({},{$set:{b:2}}) successfully completes.
What is the output of db.coll.find()?
(Choose 1)
a. [{_id:1, b:2}, {_id:2, b:2}] b. [{_id:1, a:1, b:2}, {_id:2, a:2}] c. [{_id:1, a:1, b:1}, {_id:2, a:2, b:2}] d. [{_id:1, a:1, b:2}, {_id:2, a:2, b:2}]
d
- Given the following documents:
{_id:1, a: “one”, b: “four”}
{_id:2, a: “two”, b: “four”}
{_id:3, a: “three”, b: “four”, c: “three”}
If the following command is executed:
db.coll.replaceOne({}, {a: “ten”, b: “five”})
What is the result?
(Choose 1)
a. {_id:1, a: "ten", b: "five"} {_id:2, a: "ten", b: "five"} {_id:3, a: "ten", b: "five"} b. {_id:1, a: "ten", b: "five"} {_id:2, a: "two", b: "four"} {_id:3, a: "three", b: "four", c: "three"} c. {_id:1, a: "ten", b: "five"} {_id:2, a: "ten", b: "five"} {_id:3, a: "ten", b: "five", c: "three"} d. {_id:1, a: "one", b: "four"} {_id:2, a: "two", b: "four"} {_id:3, a: "three", b: "four", c: "three"}
b
- Given the collection called coll, with only the following documents,
{
_id:1,
a:1,
b:1
},
{
_id:2,
a:2
}
The update operation db.coll.updateMany({},{$set:{b:2}}) successfully completes.
What is the output of db.coll.find()?
(Choose 1)
a. [{_id:1, b:2}, {_id:2, b:2}] b. [{_id:1, a:1, b:2}, {_id:2, a:2}] c. [{_id:1, a:1, b:1}, {_id:2, a:2, b:2}] d. [{_id:1, a:1, b:2}, {_id:2, a:2, b:2}]
d
- Given the following example document from the movie collection:
{
_id: ObjectId(“62872ccd590c3c06d78af00d”),
genres: [ “Drama”, “Romance”, “War” ],
title: “A.B.”,
year: 1921,
tomatoes: { rating: 3.9, votes: 507, id: “76” },
countries: [ “USA” ],
classic : false
}
All documents in this collection have the same schema.
What command updates the value of the classic field to true for all documents with a year value less than 2000?
(Choose 1)
a. db.movie.updateOne({ year: { $lt: 2000 } }, { $set: { classic: true } }, { multi: true }) b. db.movie.updateMany({ year: { $lt: 2000 } }, { $set: { classic: true } }) c. db.movie.updateMulti({ year: { $lt: 2000 } }, { $set: { classic: true } }) d. db.movie.updateBulk({ year: { $lt: 2000 } }, { $set: { classic: true } })
b