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
Q

what can be a value in document db

A

any data type

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

references

A

including links from one document in another which normalises the db

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

what are some benefits of using referencing

A

can represent more complex many-to-many relationships
good for large hierarchical datasets

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

what is a negative of using referencing

A

requires follow up queries to find all the data you need

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

embedded data

A

having a doc inside another via an array

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

embedded data positive

A

can get all the data in one call using less queries

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

negative of embedded data

A

the db isn’t normalised an not all values are atomic

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

data model

A

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

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

which two parts of the CAP approach does mongodb focus on

A

consistency and partition tolerance

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

what are the different parts of the mongodb structure and how do they relate to eachother

A

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

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

what is mongosh

A

an interactive shell that is a fully functional javascrips interpreter

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

in mongo what happens when you USE a db but it doesnt exist

A

mongo creates it

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

db.dropDatabase

A

deleted the db

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

show dbs

A

shows your databases

39
Q

what does db.collection.findOne({“title”: /c/}) do

A

finds all the attributes with c in the name (regular expressions)

40
Q

mongod

A

db instance

41
Q

CRUD

A

create
read
update
delete

42
Q

db.collection.insertOne()

A

inserts a single document into the collection and if the collection doesnt exist then mongo creates it

43
Q

what does the backtick do``

A

evaluates the contents within it

44
Q

db.collection.find

A

prints all docs in the collection

45
Q

db.collection.find(<query>)</query>

A

prints all docs in the collection that match the query

46
Q

db.collection.find(<query>).count</query>

A

prints the number of docs in the collection that match the query

47
Q

db.collection.findOne()

A

prints the first doc that matches the query

48
Q

what happens if the projection and query are both null (db.collection.findOne(<query>,<projection>)</projection></query>

A

prints out all the fields in the first document

49
Q

db.collection.updateOne((<query,<update>,<options>)</options></update>

A

updates the command matching the query

50
Q

db.collection.updateMany((<query,<update>,<options>)</options></update>

A

updates all documents matching the query

51
Q

in which two ways do we enforce constraints in mongodb

A

validators and indexes

52
Q

validator

A

ensure fields meet specific criteria
e.g. required, not null, datatype

53
Q

indexes

A

can enforce uniqueness and speeds up searching by organising data and provide multiplicity constraints
e.g. unique

54
Q

index 1

A

ascending

55
Q

index -1

A

descending

56
Q

how do we use indexes to create m:n relationships

A

creating a compound index for the join table and make them unique

57
Q

validator + index

A

exactly 1

58
Q

using index means

A

at most one

59
Q

using validator means

A

at least one

60
Q

what is the main difference between validators and indexes when being created

A

validators are created while creating the collection whilst indexes can be created after

61
Q

what is the key symbol for a query

A

$

62
Q

$gt

A

greater than

63
Q

$eq

A

equal

64
Q

$and

A

AND

65
Q

$or

A

OR

66
Q

$regex

A

regular expression

67
Q

what does {} signify in a findOne()

A

the condition

68
Q

how can we ensure total participation using a validator

A

required: [x,y]

69
Q

,

A

implicit AND

70
Q

what does a regex start and end with

A

/ and $/

71
Q

^ meaning in regex

A

start of the string

72
Q

. meaning in regex

A

any character

73
Q

{5,} meaning in regex

A

at least 5

74
Q

i meaning in regex

A

case insensitive

75
Q

?! meaning in regex

A

negative lookahead; checks if the pattern does not follow the current position

76
Q

?= meaning in regex

A

positive lookahead; checks if the pattern follows the current position

77
Q
  • meaning in regex
A

order of string not important

78
Q

what is the cursor in mongodb

A

a pointer that keeps the value returned by find()

79
Q

how do you retrieve documents as a constant value from the cursor

A

using loops

80
Q

.sort({item: 1/-1})

A

sorts the returned items in ascending or descending order

81
Q

how do we show which attributes we want to be included in the result of find()

A

at the v end of the query
name: 1

82
Q

how do we omit the _id from our find() result

A

_id: 0
can only be used with _id as its automatically given

83
Q

how do we use IN in mongodb

A

type: {$in:[‘food’]}

84
Q

how do we search in an embedded document

A

need to fill all subdocuments fields and in the same order when making your query

85
Q

how do we get the first value in an array when writing a query

A

e.g. ‘ratings.0’

86
Q

what does $elemMatch do

A

returns if at least one array element satisfies the entire condition

87
Q

why do we need to use $elemMatch

A

if we dont and we have multiple conditions then mongo just does an implicit or

88
Q

what is the mongo equivalent of group by having

A

$group $match

89
Q

aggregation pipeline

A

documents go through a pipeline of operations until aggregated

90
Q

how do you use count to find the number of documents in the collection

A

$count : “name”

91
Q

how do you count a specific attribute in a document in a collection

A

$match before counting

92
Q

db.createView(viewName, collection, pipeline, options)

A

temporarily returns a collection that will not be kept in the database

93
Q

$lookup

A

creates a cross product of two collections based on a common field

94
Q

$unwind

A

deconstructs/ flattens an array into individual docs