yiiiiha
This commit is contained in:
parent
125107da50
commit
4cd36ea3fc
2 changed files with 34 additions and 2 deletions
|
|
@ -1,6 +1,28 @@
|
|||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
const mongoose = require("mongoose");
|
||||
|
||||
const url = "mongodb://devroot:devroot@localhost:27017/fsopen?authSource=admin";
|
||||
mongoose.set("strictQuery", false);
|
||||
|
||||
mongoose.connect(url);
|
||||
|
||||
const noteSchema = new mongoose.Schema({
|
||||
content: String,
|
||||
important: Boolean,
|
||||
});
|
||||
|
||||
noteSchema.set("toJSON", {
|
||||
transform: (document, returnedObject) => {
|
||||
returnedObject.id = returnedObject._id.toString();
|
||||
delete returnedObject._id;
|
||||
delete returnedObject.__v;
|
||||
},
|
||||
});
|
||||
|
||||
const Note = mongoose.model("Note", noteSchema);
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
let notes = [
|
||||
|
|
@ -24,7 +46,9 @@ app.get("/", (request, response) => {
|
|||
});
|
||||
|
||||
app.get("/api/notes", (request, response) => {
|
||||
Note.find({}).then((notes) => {
|
||||
response.json(notes);
|
||||
});
|
||||
});
|
||||
|
||||
app.post("/api/notes", (request, response) => {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,15 @@ const note = new Note({
|
|||
important: true,
|
||||
});
|
||||
|
||||
note.save().then((result) => {
|
||||
/* note.save().then((result) => {
|
||||
console.log("note saved!");
|
||||
mongoose.connection.close();
|
||||
});
|
||||
*/
|
||||
|
||||
Note.find({}).then((result) => {
|
||||
result.forEach((note) => {
|
||||
console.log(note);
|
||||
});
|
||||
mongoose.connection.close();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue