-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbcheck.js
More file actions
37 lines (27 loc) · 1 KB
/
Copy pathdbcheck.js
File metadata and controls
37 lines (27 loc) · 1 KB
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
// Import the mongoose module
const mongoose = require("mongoose");
// Set up default mongoose connection
const mongoDB = "mongodb://127.0.0.1/my_database";
mongoose.connect(mongoDB, { useNewUrlParser: true, useUnifiedTopology: true });
// Get the default connection
const db = mongoose.connection;
// Bind connection to error event (to get notification of connection errors)
db.on("error", console.error.bind(console, "MongoDB connection error:"));
// Define a schema
const Schema = mongoose.Schema;
const messageSchema = new Schema({
user_name:String,
topic: String,
msgbody: String,
status: String
});
// Compile model from schema
const messageModel = mongoose.model("messagemodel", messageSchema);
// Create an instance of model SomeModel
const messageInst = new messageModel({ user_name: "vlad03",topic:"topic01",msgbody:" SMS message1",status:"_new"});
// Save the new model instance, passing a callback
messageInst.save((err) => {
if (err)
return handleError(err);
// saved!
});