What is CRUD?

Create, Read, Update, and Delete (CRUD) are the four basic functions that models should be able to do, at most.

Error message: Process finished with exit code -1073741819 (0xC0000005)

问题描述:
idea中启动项目报 Process finished with exit code -1073741819 (0xC0000005) ,如图所示:

问题解决:
原因:经过多方查证,问题最终定位在金山词霸2016上,如果开启了金山词霸的划译功能,就会出现此错误,具体原理有待研究。在关闭金山词霸时,有时idea也会自动关闭。

​ 解决:关掉金山词霸,或者把金山词霸的划译功能关掉,然后重启idea,再运行项目就没问题了。经过尝试,发现只要在IDEA第一次打开并运行的时候,没有开启金山词霸的划译功能,那么之后就算开启也不会有问题。所以如果一定需要用金山,就先打开idea运行项目,在打开金山,或者直接把金山的划译功能关掉就可以了。

!!!注意:金山词霸划译与idea2018.3+版本不兼容

MONGODB

structure

Data in MongoDB is made up of three types of components: databases, collections, and documents. The database sits at the top of the hierarchy, collections at the next level, and documents at the bottom.

img

operation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const mongoose = require("mongoose");
const { stringify } = require("querystring");

//open the connection
mongoose.connect("mongodb+srv://dxexperiments-user:DrEuMg7KfFImh774@dxvignettes.vtnenqy.mongodb.net/");

// this lays out the foundation for every new fruit document that will be added to the database
const fruitSchema = new mongoose.Schema({
name: String,
rating:{
type:Number,
min: 1,
max: 10
},
review: String
});

// first parameter, name of the collection(mongodb will convert this string into a pluralize form to create your collection); so we created a new collection called Fruits
// second parameter: It is the schema of the collection.
const Fruit = mongoose.model("Fruit", fruitSchema);


// creating fruit document from Fruit model, means the document need to stick to this schema
const fruit = new Fruit({
name:"apple",
rating: 6,
review:"well, average."
});

//save fruit document into the Fruist collection inside of the DATABASE
// fruit.save();

const personSchema = new mongoose.Schema({
name: String,
age:Number
});


const grape = new Fruit({
name: "grape",
rating: 7,
review: " I really like it"
});

const kiwi = new Fruit({
name: "kiwi",
rating: 6,
review: " I really like it"
});

const pineapple = new Fruit({
name: "pineapple",
rating: 9,
review: " I really like it"
});
// Fruit.insertMany([kiwi,grape,pineapple]);

Fruit.find().exec()
.then((fruits) => {
//close the connection
mongoose.connection.close();
fruits.forEach((fruit) => {
console.log(fruit.name);
});
})
.catch((error) => {
console.error('Error retrieving fruits:', error);
});


data validation with mongoose:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const fruitSchema = new mongoose.Schema({
name:
{
type: String,
required: [true, 'Why no name?']
},
rating:
{
type:Number,
min: 1,
max: 10
},
review: String
});

delete and update

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Fruit.updateOne({_id:"648dc4fdd4b6dda3193f73b3"}, {name: "change"});
Fruit.deleteOne({name: "kiwi"})
.then(() => {
console.log("Kiwi deleted successfully");
})
.catch((error) => {
console.error("Error deleting kiwi:", error);
});


Person.deleteMany({name: "Dan"}) .then(() => {
console.log("Dan deleted successfully");
})
.catch((error) => {
console.error("Error deleting kiwi:", error);
});