MongoDB MCQs – Data Validation

11.) Which keyword in JSON schema specifies the data type of a field?

A) type
B) format
C) validate
D) schema

Answer: Option A

Explanation: The type keyword defines the data type of a field, such as string, number, or array.

12.) Which JSON schema keyword ensures that an array contains unique items?

A) uniqueArray
B) uniqueItems
C) distinct
D) unique

Answer: Option B

Explanation: The uniqueItems keyword ensures that all elements in an array are unique.

13.) Which keyword in JSON schema specifies a range of allowed numeric values?

A) range
B) between
C) minimum and maximum
D) limits

Answer: Option C

Explanation: The minimum and maximum keywords define a numeric range for a field.

14.) In JSON schema, which keyword validates string formats, such as email or date?

A) pattern
B) type
C) match
D) format

Answer: Option D

Explanation: The format keyword validates strings against specific formats like email, date, or URI.

15.) How can you remove validation rules from a collection?

A) How can you remove validation rules from a collection?
B) Use collMod with an empty validation object
C) db.collection.dropValidation()
D) Modify the schema to default

Answer: Option B

Explanation: The collMod command can remove validation rules by setting the validation object to {}.

16.) Which validation action is the most restrictive?

A) warn
B) strict
C) moderate
D) error

Answer: Option D

Explanation: The error validation action is the most restrictive, rejecting any document that fails validation.

17.) How can you bypass validation rules for a specific operation?

A) Use the –bypassValidation option
B) Use the skipValidation command
C) Use the bypassDocumentValidation: true option in the query
D) Modify the collection schema

Answer: Option C

Explanation: The bypassDocumentValidation: true option allows skipping validation rules for a specific operation.

18.) Which MongoDB version introduced schema validation?

A) 2.4
B) 3.2
C) 4.0
D) 4.2

Answer: Option B

Explanation: Schema validation was introduced in MongoDB 3.2, allowing JSON schema enforcement.

19.) Which JSON schema keyword specifies the maximum number of items allowed in an array?

A) maxItems
B) maxArraySize
C) maximum
D) arrayLimit

Answer: Option A

Explanation: The maxItems keyword sets an upper limit on the number of elements in an array field.

20.) What does the pattern keyword in JSON schema validate?

A) Numeric fields
B) Array elements
C) String fields using a regular expression
D) Document size

Answer: Option C

Explanation: The pattern keyword validates string fields against a specified regular expression.

Leave a Reply

Your email address will not be published. Required fields are marked *