-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
37 lines (27 loc) · 901 Bytes
/
test.js
File metadata and controls
37 lines (27 loc) · 901 Bytes
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
const mongoose = require('mongoose');
const Post = require('./database/models/Post');
mongoose.connect('mongodb://localhost/node-js-test-blog');
// find specific by ID
// Post.findById("5bca4123131f12d184314d6c", (error, post) => {
// console.log(error, post);
// })
// find all query
Post.find({}, (error, post) => {
console.log(error, post)
})
// insert query for Post database
// Post.create({
// title: "My First Blog",
// description: "Blog post description",
// content: 'lorem ipsum'
// }, (error, post) => {
// console.log(error, post)
// })
// find and Update using ID
// Post.findByIdAndUpdate("5bca4123131f12d184314d6c", {
// title: "This is Ibad siddiqui's blog"
// }, (error, post) => {
// console.log(error, post)
// })
// find and remove by ID
// Post.findByIdAndRemove("5bca4123131f12d184314d6c", (error, post) => console.log(error, post))