-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor(): write a script to add data to database
- delete old data from the database - added a new Post and comment data - change the type of _id in Comment Model
- Loading branch information
1 parent
2927835
commit cb9069a
Showing
10 changed files
with
543 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "attach", | ||
"name": "Attach by Process ID", | ||
"processId": "${command:PickProcess}" | ||
}, | ||
|
||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const Comment = require('../models/comment-model'); | ||
const Post = require('../models/posts-model'); | ||
var mongoose = require('mongoose'); | ||
import Post from '../interfaces/post.interface'; | ||
import Comments from '../interfaces/comment.interface'; | ||
const samplePosts = require("./sample-posts"); | ||
const sampleComments = require("./sample-comments"); | ||
|
||
function insertPostsAndComments() { | ||
|
||
let dbURL = 'mongodb://localhost:27017/reduxtagram-server'; | ||
|
||
mongoose.connect(dbURL, { useNewUrlParser: true}, function(err: any){ | ||
if(err) { | ||
console.log('Error connecting to: ', dbURL) | ||
} | ||
else { | ||
console.log('Connected to : ' + dbURL); | ||
|
||
Post.collection.insert(samplePosts.default, async function (err: any, docs: any) { | ||
if (err){ | ||
return console.error(err); | ||
} else { | ||
const posts = await Post.find({}) | ||
.exec() | ||
.catch((err: any) => console.log("err occured in fetching posts", err)); | ||
|
||
const comments: Comments[] = [] | ||
posts.map((post:any, i: any) => { | ||
comments.push({ | ||
...sampleComments.default[i], | ||
postId: post._id | ||
}) | ||
}); | ||
|
||
Comment.collection.insert(comments, async function(err: any, docs: any){ | ||
if(err) { | ||
return console.error(err) | ||
} else { | ||
const comments = await Comment.find({}) | ||
.exec() | ||
.catch((err: any) => console.log("err occured in fetching comments", err)) | ||
console.log("comments"); | ||
console.log(comments); | ||
} | ||
}) | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
insertPostsAndComments(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.