Quiz Chapter 3: Which of the following commands will add new fields to the updated documents?

Problem:

Given a pets collection where each document has the following structure and fields:

{
 "_id": ObjectId("5ec414e5e722bb1f65a25451"),
 "pet": "wolf",
 "domestic?": false,
 "diet": "carnivorous",
 "climate": ["polar", "equatorial", "continental", "mountain"]
}

Which of the following commands will add new fields to the updated documents?
A.
db.pets.updateMany({ “pet”: “cat” },
{ “$set”: { “climate”: “continental” }})
B.
db.pets.updateMany({ “pet”: “cat” },
{"$set": { “domestic?”: true, “diet”: “mice” }})
C.
db.pets.updateMany({ “pet”: “cat” },
{ “$push”: { “climate”: “continental”,
“look”: “adorable” } })
D.
db.pets.updateMany({ “pet”: “cat” },
{ “$set”: { “type”: “dangerous”,
“look”: “adorable” }})


As the question, it asked which commands would add new fields (it’s at least 2 because of ‘s’, not field)

< deleted reason: potential answer>

Is there any problem or mistake with the answer (the letter “s” in “fields”)?

Please give me a respond and tell me the exact answer!

Hi @Hung_N_A,

Welcome to the MongoDB Community Forums :sparkles:

The options to the question are correct from our end which is explained in the detailed answer to the question. However, we didn’t disclose the answers/correct options in the public forums.

Also as per the problem statement, it also says commands with s which clearly means there will be multiple correct options!

Moreover, I will update it to field/s to avoid further confusion if ever encountered again by any learner.

Thanks,
Kushagra

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.