MongoDB Questions and Answers – ObjectId

This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “ObjectId”.

1. Object_Id is similar to _________ key in Relational Databases.
a) primary
b) secondary
c) composite
d) all of the mentioned
View Answer

Answer: a
Explanation: Object_Id is unique and cannot be changed.

2. Which of the field is reserved for use as a primary key?
a) _id
b) _uid
c) _uuid
d) All of the mentioned
View Answer

Answer: a
Explanation: ID value value must be unique in the collection, is immutable, and may be of any type other than an array.

3. Point out the wrong statement.
a) The field names cannot start with the dollar sign ($) character
b) The field names cannot contain the dot (.) character
c) The field names cannot contain the null character
d) None of the mentioned
View Answer

Answer: d
Explanation: Documents have certain restrictions on field names.

advertisement
advertisement

4. To ensure functioning replication, do not store values that are of the _______ regular expression type in the _id field.
a) JSON
b) XML
c) JScript
d) None of the mentioned
View Answer

Answer: d
Explanation: The _id field may contain values of any BSON data type, other than an array.

5. The ______ field is always the first field in the document.
a) _id
b) id
c) Ob_id
d) None of the mentioned
View Answer

Answer: a
Explanation: Updates that include renaming of field names may result in the reordering of fields in the document.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. __________ returns the JavaScript representation in the form of a string literal.
a) toStringJava()
b) toString()
c) String()
d) none of the mentioned
View Answer

Answer: b
Explanation: In previous versions, toString() returns the hexadecimal string representation, which as of version 2.2 can be retrieved by the str property.

7. Which of the following query is used to generate a new ObjectId, use the ObjectId() constructor with no argument?
a) x = ObjectIdAdd()
b) x = addObjectId()
c) x = ObjectId()
d) none of the mentioned
View Answer

Answer: c
Explanation: ObjectId() constructor is used with no argument for new object.
advertisement

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Books in MongoDB.

advertisement

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.