Guest User

Untitled

a guest
Nov 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const Book = require("../model/book");
  2.  
  3. // dummy data
  4. const books = [
  5. {name: "Name of the Wind", genre: "Fantasy"},
  6. {name: "The Final Empire", genre: "Fantasy"},
  7. {name: "The Long Earth", genre: "Sci-Fi"},
  8. {name: "The Hero of Ages", genre: "Fantasy"},
  9. {name: "The Colour of Magic", genre: "Fantasy"},
  10. {name: "The Light Fantastic", genre: "Fantasy"},
  11. {name: "드래곤볼", genre: "Sci-Fi"}
  12. ];
  13.  
  14. Book.collection.insert(books, function (err, docs) {
  15. if (err){
  16. return console.error(err);
  17. } else {
  18. console.log("Multiple documents inserted to Collection");
  19. }
  20. });
  21.  
  22. const mongoose = require('mongoose');
  23. const Schema = mongoose.Schema;
  24.  
  25. const bookSchema = new Schema({
  26. name: String,
  27. genre: String
  28. });
  29.  
  30. module.exports = mongoose.model("Book", bookSchema);
Add Comment
Please, Sign In to add comment