Understanding NoSQL Databases: MongoDB, Exams of Computer Science

A comprehensive overview of different types of nosql databases, with a focus on mongodb. It covers the key features and characteristics of mongodb, including its flexible data model, scalability, and expressive query language. The document also explores topics such as data types, objectid structure, data modeling best practices, aggregation, indexing, sharding, and replication in mongodb. Additionally, it addresses common mongodb operations like inserting, updating, and removing data. The information presented in this document can be valuable for university students studying database systems, software engineering, or cloud computing, as well as for lifelong learners interested in understanding the evolution of database technologies beyond traditional relational databases.

Typology: Exams

2023/2024

Available from 09/21/2024

ROCKY-B
ROCKY-B 🇰🇪

4.4

(16)

40K documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MONGODB EXAM QUESTIONS AND ANSWERS
What are some different types of NoSQL databases? - Answers -There are four types of
NoSQL database:
Document store NoSQL database
Graph base NoSQL database
Key value store NoSQL database
A column store NoSQL database
What kind of NoSQL database is MongoDB? - Answers -MongoDB is a document
oriented database. It stores data in the form of BSON structure based documents.
These documents are stored in collections.
Compare SQL databases and MongoDB at a high level. - Answers -SQL (relational)
databases store data in form of tables, rows and columns. This data is stored in a pre-
defined schema which is not very much flexible for today's real-world highly growing
applications. MongoDB in contrast uses a flexible document structure which places the
responsibility for data modeling mostly on the other parts of the application. A given
collection may hold documents with different structure as long as the application is
programmed to expect such variation.
Which are the most important features of MongoDB? - Answers -- Flexible data model
in form of documents (schema-less)
- Agile and highly scalable database (Sharding)
- Faster than traditional databases
- Expressive query language (dynamic, querying nested documents)
- Avoids the "impedance mismatch" between object and relational models when a
relational database is used with an object-oriented application.
MongoDB uses BSON to represent document structures. True or False? - Answers -
True
What is a Namespace in MongoDB? - Answers -A Namespace is the concatenation of
the database name and collection name. For e.g. school.students with school as the
database and students as the collection
What is the syntax to create a collection in MongoDB? - Answers -
db.createCollection(name,options)
What are different type of data types in mongodb? - Answers -String
Number
Date
Buffer
Boolean
ObjectId
pf3
pf4
pf5

Partial preview of the text

Download Understanding NoSQL Databases: MongoDB and more Exams Computer Science in PDF only on Docsity!

MONGODB EXAM QUESTIONS AND ANSWERS

What are some different types of NoSQL databases? - Answers -There are four types of NoSQL database: Document store NoSQL database Graph base NoSQL database Key value store NoSQL database A column store NoSQL database What kind of NoSQL database is MongoDB? - Answers -MongoDB is a document oriented database. It stores data in the form of BSON structure based documents. These documents are stored in collections. Compare SQL databases and MongoDB at a high level. - Answers -SQL (relational) databases store data in form of tables, rows and columns. This data is stored in a pre- defined schema which is not very much flexible for today's real-world highly growing applications. MongoDB in contrast uses a flexible document structure which places the responsibility for data modeling mostly on the other parts of the application. A given collection may hold documents with different structure as long as the application is programmed to expect such variation. Which are the most important features of MongoDB? - Answers -- Flexible data model in form of documents (schema-less)

  • Agile and highly scalable database (Sharding)
  • Faster than traditional databases
  • Expressive query language (dynamic, querying nested documents)
  • Avoids the "impedance mismatch" between object and relational models when a relational database is used with an object-oriented application. MongoDB uses BSON to represent document structures. True or False? - Answers - True What is a Namespace in MongoDB? - Answers -A Namespace is the concatenation of the database name and collection name. For e.g. school.students with school as the database and students as the collection What is the syntax to create a collection in MongoDB? - Answers - db.createCollection(name,options) What are different type of data types in mongodb? - Answers -String Number Date Buffer Boolean ObjectId

Array Are null values allowed? - Answers -Yes, but only for the members of an object. A null cannot be added to the database collection as it isn't an object. But {}can be added. Explain the structure of ObjectID in MongoDB. - Answers -ObjectID is a 12-byte BSON type with:

  • 4 bytes value representing seconds
  • 3 byte machine identifier
  • 2 byte process id
  • 3 byte counter When creating a data model in MongoDB what are the points need to be taken in consideration? - Answers -Points need to be taken in consideration are
  • Design your schema according to user requirements
  • Combine objects into one document if you use them together. Otherwise, separate them
  • Do joins while write, and not when it is on read
  • Optimize your data model for the most important use cases
  • Do complex aggregation in the schema Write the command to insert a document in a database called school and collection called persons (using the MongoDB shell). - Answers -use school; ex: db.persons.insert( { name: "kadhir", dept: "CSE" } ) In Mongo Shell, how would you add a new column 'status' containing a default value of 'new' to an existing document {_id: 7, name: "Susan"} in a people collection? - Answers -db.people.updateOne({_id: 7}, {$set: {status: "new"}}); How would you remove the property "points" from the object {_id: 7, name: Susan, points: 88} in the people collection? - Answers -db.people.update({_id: 7}, {$unset: {points: 1"}}, {mullti: true}); How would you remove the property "points" from all objects in the people collection? - Answers -db.people.updateOne({_id: 7}, {$unset: {points: 1"}}); How would you find documents in the inventory collection that have a status of "A" and a qty < 30 or a name starting with the letter "p"? - Answers -db.inventory.find( { status: "A", $or: [ { qty: { $lt: 30 } }, { item: /^p/ } ] } ) What are the differences between updateOne and replaceOne? - Answers -updateOne will only modify parts of the document, as specified in the update modifier, while replaceOne, will replace the first matching document with the supplied document.

What's a Master or Primary? - Answers -This is a node/member which is currently the primary and processes all writes for the replica set. During a failover event in a replica set, a different member can become primary. What's a Secondary or Slave? - Answers -A secondary is a node/member which applies operations from the current primary. This is done by tailing the replication oplog (local.oplog.rs). Replication from primary to secondary is asynchronous, however, the secondary will try to stay as close to current as possible (often this is just a few milliseconds on a LAN). By default, MongoDB writes and reads data from both primary and secondary replica sets. True or False. - Answers -False. MongoDB writes data only to the primary replica set. Should I start out with sharded or with a non-sharded MongoDB environment? - Answers -starting unsharded for simplicity and quick startup unless your initial data set will not fit on single servers. Upgrading to sharding from unsharded is easy and seamless, so there is not a lot of advantage to setting up sharding before your data set is large. How can I see the connections used by mongos? - Answers - db._adminCommand("connPoolStats"); What is Mongoose? - Answers -Mongoose is a MongoDB object modeling tool, or ODM (Object Document Mapper), written in JavaScript and designed to work in an asynchronous environment Is there a way to access the ObjectId constructor from Mongoose? - Answers -Yes, you can find the ObjectId constructor on require('mongoose').Types. Here is an example: var mongoose = require('mongoose'); var id = mongoose.Types.ObjectId(); id is a newly generated ObjectId. What is difference between dependencies and devDependencies? - Answers - dependencies are modules your project depends on. devDependencies are modules you use to develop your project. Examples of dependencies are request, through2 and concat-stream. Examples of devDependencies are grunt, mocha, eslint, tape, and browserify.

When should we embed one document within another in MongoDB? - Answers -You should consider embedding documents for:

  • 'contains' relationships between entities
  • One-to-many relationships (if the many is not very large)
  • Performance reasons How do you copy all objects from one collection to another? - Answers -In the mongo shell, you can use the following operation to duplicate the entire collection: db.source.copyTo(newCollection) Warning: When using db.collection.copyTo() check field types to ensure that the operation does not remove type information from documents during the translation from BSON to JSON. Consider using cloneCollection() to maintain type fidelity. The db.collection.copyTo() method uses the eval command internally. As a result, the db.collection.copyTo() operation takes a global lock that blocks all other read and write operations until the db.collection.copyTo() completes. Also consider the cloneCollection command that may provide some of this functionality. What is the syntax to drop a collection in MongoDB? - Answers -db.collection.drop() What happens when a document is updated on a chunk that is being migrated? - Answers -The update will go through immediately on the old Shard and then the change will be replicated to the new Shard before ownership transfers. To do Safe backups what features are used in MongoDB? - Answers -The journaling is the feature in MongoDB that you can use to do safe backups. (duplicate) What is the command syntax for inserting a document in MongoDB? - Answers -database.collection.insert(document) What is the role of profiler in MongoDB? - Answers -MongoDB includes a database profiler which shows performance characteristics of each operation against the database. With this profiler you can find queries (and write operations) which are slower than they should be and use this information for determining when an index is needed. If you remove a document from database in MongoDB, does MongoDB remove it from disk? - Answers -Yes. If you remove a document from database, MongoDB will remove it from disk too. Does MongoDB database use tables for storing records? - Answers -No, Instead of tables, MongoDB uses "Collection" to store data. How does Journaling work in MongoDB? - Answers -When running with journaling, MongoDB stores and applies write operations in memory and in the on-disk journal before the changes are present in the data files on disk. Writes to the journal are

mongostat, and/or the MongoDB Management Service (MMS) Specifically, the locks document in the output of serverStatus, or the locks field in the current operation reporting provides insight into the type of locks and amount of lock contention in your mongod instance. To terminate an operation, use db.killOp(). How does MongoDB sort queries in sharded environments? - Answers -If you call the cursor.sort() method on a query in a sharded environment, the mongod for each shard will sort its results, and the mongos merges each shard's results before returning them to the client. How do you determine the size of an index? - Answers -To check the sizes of the indexes on a collection, use db.collection.stats().