no sql Flashcards

1
Q

what are the 4 types of data

A

structured and unstructured
dynamic and static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

dynamic

A

changing frequently

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

static

A

never changes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

strcutured

A

formal predefined
easy to store and process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

unstructured

A

e.g. audio, image, music
usually still has internal structural properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

sharding data

A

splitting the data to allow concurrent/parallel access using multiple machines
can simultaneously access each shard

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

in which two ways can we scale databases

A

vertically and horizontally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

vertical scaling

A

upgrading hardware e.g. increasing memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is the limitaiton of vertical scaling

A

limited by the amount of cpu ram disk etc that can be configured on a single machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

horizontal scaling

A

adding more machines which requires shading and replication so you can work with them simultaneously

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is the limitation of horizontal scaling

A

read-to-write ratio and communication overhead

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

in which three ways can we benefit form parallelisation

A

maximise the fraction of the program that can be parallelised
balance the work load and parallel process
minimise the time spent on communication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how does the two phase commit protocol work

A

the coordinator requests cote for commit and the participants either approve or reject
if all participants accept then everything gets committed at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is the issue with two phase commit

A

hard to find a time where all servers are ready to commit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the CAP theorem

A

any distributed database with shared data can have at most 2/3
usually sacrificing consistency

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what are the three components of cap theorem

A

consistency; every node always sees the same data at the same time
availability; the system continues operating even if nodes crash or software or hardware is down
partition tolerance; the system works well when distributed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

what are the BASE properties

A

basically available; the system guaranteed availability
soft state; system state may change over time
eventual consistency; will eventually become consistent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what does it mean for a db to be eventually consistent

A

if all replicas will gradually become consistent in the absence of updates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what makes no sql no sql

A

no strict schema requirements
no strict adherence to acid properties
consistency is traded in favour of availability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

document database/store

A

loosely structured set of key value pairs in documents encapsulate and encode data in some standard formats/encodings
treated as a whole
query languages can help retrieve documents based on their contents
addressed in the db via the unique key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

in mongo what is the primary key

A

key; “_id”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

sorted ordered column-oriented stores

A

columns are grouped in column families which data is stored in rather than tables
each unit of data is a set of key value pairs identified by row-key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

graph db

A

everything is stored as an edge node or attribute
each node and edge can have any number attributes and can be labelled which narrows searches

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

what do document db use instead of an fk

A

embedded documents and referencing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
what can be a value in document db
any data type
26
references
including links from one document in another which normalises the db
27
what are some benefits of using referencing
can represent more complex many-to-many relationships good for large hierarchical datasets
28
what is a negative of using referencing
requires follow up queries to find all the data you need
29
embedded data
having a doc inside another via an array
30
embedded data positive
can get all the data in one call using less queries
31
negative of embedded data
the db isn't normalised an not all values are atomic
32
data model
displays a set of tables and the relationship between them providing a blueprint so you can identify which data is important and what should be maintained
33
which two parts of the CAP approach does mongodb focus on
consistency and partition tolerance
34
what are the different parts of the mongodb structure and how do they relate to eachother
an instance has 0/more databases a database has 0/more collections a collection has 0/more documents a document has 1/more fields/attributes
35
what is mongosh
an interactive shell that is a fully functional javascrips interpreter
36
in mongo what happens when you USE a db but it doesnt exist
mongo creates it
37
db.dropDatabase
deleted the db
38
show dbs
shows your databases
39
what does db.collection.findOne({"title": /c/}) do
finds all the attributes with c in the name (regular expressions)
40
mongod
db instance
41
CRUD
create read update delete
42
db.collection.insertOne()
inserts a single document into the collection and if the collection doesnt exist then mongo creates it
43
what does the backtick do``
evaluates the contents within it
44
db.collection.find
prints all docs in the collection
45
db.collection.find()
prints all docs in the collection that match the query
46
db.collection.find().count
prints the number of docs in the collection that match the query
47
db.collection.findOne()
prints the first doc that matches the query
48
what happens if the projection and query are both null (db.collection.findOne(,)
prints out all the fields in the first document
49
db.collection.updateOne((,)
updates the command matching the query
50
db.collection.updateMany((,)
updates all documents matching the query
51
in which two ways do we enforce constraints in mongodb
validators and indexes
52
validator
ensure fields meet specific criteria e.g. required, not null, datatype
53
indexes
can enforce uniqueness and speeds up searching by organising data and provide multiplicity constraints e.g. unique
54
index 1
ascending
55
index -1
descending
56
how do we use indexes to create m:n relationships
creating a compound index for the join table and make them unique
57
validator + index
exactly 1
58
using index means
at most one
59
using validator means
at least one
60
what is the main difference between validators and indexes when being created
validators are created while creating the collection whilst indexes can be created after
61
what is the key symbol for a query
$
62
$gt
greater than
63
$eq
equal
64
$and
AND
65
$or
OR
66
$regex
regular expression
67
what does {} signify in a findOne()
the condition
68
how can we ensure total participation using a validator
required: [x,y]
69
,
implicit AND
70
what does a regex start and end with
/ and $/
71
^ meaning in regex
start of the string
72
. meaning in regex
any character
73
{5,} meaning in regex
at least 5
74
i meaning in regex
case insensitive
75
?! meaning in regex
negative lookahead; checks if the pattern does not follow the current position
76
?= meaning in regex
positive lookahead; checks if the pattern follows the current position
77
* meaning in regex
order of string not important
78
what is the cursor in mongodb
a pointer that keeps the value returned by find()
79
how do you retrieve documents as a constant value from the cursor
using loops
80
.sort({item: 1/-1})
sorts the returned items in ascending or descending order
81
how do we show which attributes we want to be included in the result of find()
at the v end of the query name: 1
82
how do we omit the _id from our find() result
_id: 0 can only be used with _id as its automatically given
83
how do we use IN in mongodb
type: {$in:['food']}
84
how do we search in an embedded document
need to fill all subdocuments fields and in the same order when making your query
85
how do we get the first value in an array when writing a query
e.g. 'ratings.0'
86
what does $elemMatch do
returns if at least one array element satisfies the entire condition
87
why do we need to use $elemMatch
if we dont and we have multiple conditions then mongo just does an implicit or
88
what is the mongo equivalent of group by having
$group $match
89
aggregation pipeline
documents go through a pipeline of operations until aggregated
90
how do you use count to find the number of documents in the collection
$count : "name"
91
how do you count a specific attribute in a document in a collection
$match before counting
92
db.createView(viewName, collection, pipeline, options)
temporarily returns a collection that will not be kept in the database
93
$lookup
creates a cross product of two collections based on a common field
94
$unwind
deconstructs/ flattens an array into individual docs