FINALS | Fundamentals of Document-Oriented Database | Advanced Database Systems

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/47

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

48 Terms

1
New cards

Inserting Document

These are the basic methods for adding data to MongoDB.

2
New cards

insertOne

To insert a single document, use the collection’s method.

3
New cards

_id

insertOne will automatically add an "____" key to the document if you do not provide one.

4
New cards

insertMany

If you need to insert multiple documents into a collection, you can use _.

5
New cards

ordered or unordered

When performing a bulk insert using insertMany, if a document halfway through the array produces an error of some type, what happens depends on whether you have opted for or __ operations.

6
New cards

Ordered inserts

This insert is the default if no order is specified.

7
New cards

Insertion

For ordered inserts, the array passed to insertMany defines the _ order. If a document produces an insertion error, no documents beyond that point in the array will be inserted.

8
New cards

Unordered inserts

In this insert, MongoDB will attempt to insert all documents, regardless of whether some insertions produce errors.

9
New cards

deleteOne and deleteMany

Removing Documents: MongoDB provides _ and _ for this purpose.

10
New cards

deleteOne

To delete the document with the "id" value of 4, we use ___ in the mongo shell.

11
New cards

deleteMany

To delete all the documents that match a filter, use __:

12
New cards

updateOne, updateMany, and replaceOne

Updating Documents: Once a document is stored in the database, it can be changed using one of several update methods: , , and .

13
New cards

updateOne and updateMany

each take a filter document as their first parameter and a modifier document, which describes changes to make, as the second parameter.

14
New cards

first parameter, second parameter

updateOne and updateMany each take a filter document as their ___ and a modifier document, which describes changes to make, as the ______ .

15
New cards

replaceOne

It fully replaces a matching document with a new one. This can be useful to do a dramatic schema migration. Example: suppose we are making major changes to a user document, which we want to move the "friends" and "enemies" fields to a "relationships" subdocument. We can change the structure of the document in the shell and then replace the database’s version with a replaceOne.

16
New cards

$set

This operator sets the value of a field. If the field does not yet exist, it will be created. $set

17
New cards

$set

This operator can even change the type of the key it modifies. For example, we want to add another value of books that the user likes; this will change the type of "favorite book" key into an array.

18
New cards

$unset

If we want to remove the “favorite book” key altogether, we can use the operator.

19
New cards

$set

We can also use ____ operator to reach in and change embedded documents.

20
New cards

updateMany

To modify all of the documents matching a filter, use. It follows the same semantics as updateOne and takes the same parameters. The key difference is in the number of documents that might be changed.

21
New cards

find()

Querying Documents: The method is used to perform queries in MongoDB. Querying returns a subset of documents in a collection.

22
New cards

first argument

Which documents get returned is determined by the ___ to find, which is a document specifying the query criteria.

23
New cards

empty query document

(i.e., db.movies.find()) will match everything in the “movies” collection. We begin restricting our search when we start adding key/value pairs to the query document.

24
New cards

Multiple conditions

It can be strung together by adding more key/value pairs to the query document, which gets interpreted as “condition1 AND condition2" > db.users.find({"username" : "John", "age" : 24})

25
New cards

$lt, $lte, $gt, and $gte

Query conditional: ___, ____, ____, and ____are all comparison operators, corresponding to

26
New cards

$ne

To query for documents where a key’s value is not equal to a certain value, you can use conditional operator, ____, which stands for “not equal.

27
New cards

$in

This operator can be used to query for a variety of values for a single key.

28
New cards

$or

This operator is more general; it can be used to query for any of the given values across multiple keys.

29
New cards

$not

This operator is useful to find all documents that don’t match a given pattern.

30
New cards

$regex

provides regular expression capabilities for pattern matching strings in queries. Regular expressions

31
New cards

Regular expression flags

(e.g., i) are allowed but not required. If we want to match not only various capitalizations of “john,” but also “johnny,” we can continue to improve our regular expression by doing this: > db.users.find({"name" : /johnny?/i})

32
New cards

Array

Querying for elements of an _ is designed to behave the way querying for scalars (string, numbers, date, etc.) does. For example, if the array is a list of fruits, like this: > db.food.insertOne({"fruit" : ["apple", "banana", "peach"] })

33
New cards

$all

If you need to match arrays by more than one element, you can use ____. This allows you to match a list of elements.

34
New cards

key.index

If we want to query for a specific element of an array, you can specify an index using the syntax _. > db.food.find({"fruit.2" : "peach"})

35
New cards

$size

matches any array with the number of elements specified by the argument. Here’s an example: > db.food.find({"fruit" : {"$size" : 3}})

36
New cards

$slice

an operator that can be used to return a subset of elements for an array key

37
New cards

first 10 comments

For example, suppose we had a blog post document and we wanted to return the __ ___: > db.blog.posts.findOne(criteria, {"comments" : {"$slice" : 10}})

38
New cards

last 10 comments

Alternatively, if we wanted the _ ___ , we could use −10: > db.blog.posts.findOne(criteria, {"comments" : {"$slice" : -10}})

39
New cards

24th

It can also return pages in the middle of the results by taking an offset and the number of elements to return: > db.blog.posts.findOne(criteria, {"comments" : {"$slice" : [23, 10]}}) 24th through 33rd

40
New cards

Embedded documents or nested documents

These are types of documents which contain a document inside another document.

41
New cards

dot notation

You can query for embedded keys using ___ : > db.people.find({"name.first" : "John", "name.last" : "Escalona"})

42
New cards

Data Modelling

In MongoDB, data has a flexible schema. It is totally different from the SQL database, where you had to determine and declare a table's schema before inserting data. MongoDB collections do not enforce document structure. The main challenge in data modeling is balancing the need of the application, the performance characteristics of the database engine, and the data retrieval patterns.

43
New cards

document structure

MongoDB collections do not enforce . The main challenge in data modeling is balancing the need of the application, the performance characteristics of the database engine, and the data retrieval patterns.

44
New cards

Embedded Data

Embedded documents capture relationships between data by storing related data in a single document structure. MongoDB documents make it possible to embed document structures in a field or array within a document. These denormalized data models allow applications to retrieve and manipulate related data in a single database operation.

45
New cards

single document structure

Embedded documents capture relationships between data by storing related data in a _ ___.

46
New cards

Denormalized

MongoDB documents make it possible to embed document structures in a field or array within a document. These __ data models allow applications to retrieve and manipulate related data in a single database operation.

47
New cards

References

These store the relationships between data by including links or references from one document to another. Applications can resolve these references to access the related data. Broadly, these are normalized data models.

48
New cards

Normalized

Applications can resolve these references to access the related data. Broadly, these are __ data models.