fullstackopen-notes/parts/3/followAlong/mongo.js

24 lines
489 B
JavaScript
Raw Normal View History

2025-06-01 23:23:55 +02:00
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,
});
const Note = mongoose.model("Note", noteSchema);
const note = new Note({
content: "HTML is easy",
important: true,
});
note.save().then((result) => {
console.log("note saved!");
mongoose.connection.close();
});