Mongo db Flashcards

1
Q

Varför Mongoose?

A

Ett bibliotek som hjälper oss med standard databas-sysslor och förenklar att skriva queries
Den förhindrar också att felaktig data kommer in i databasen med hjälp av databas-schema.

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

Hur skapar vi koppling till databasen?

A
const mongoose = require("mongoose"); 
mongoose.connect("mongodb://localhost/backend1"); 
const db = mongoose.connection;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Hur skapar man ett nytt shema?

A

const userSchema = new mongoose.Schema({

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

Hur skapar man en modell?

A

const User = mongoose.model(“User”, userSchema);

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

Hur uppdaterar man en modell?

A
  1. Ändra på en modellinstans och anropa .save()
  2. .updateOne
  3. .updateMany
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Hur tar man bort modeller?

A

.deleteOne( )

.deleteMany( )

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

Hur kan man göra en left join?

A

.populate ( )

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