kbo25

Untitled

Apr 11th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ---------- model (Book.js) --------
  2. // ...
  3. const bookSchema = new mongoose.Schema({
  4.   title: {
  5.       type: 'string',
  6.       require: 'true'
  7.   },
  8.   author: {
  9.       type: 'string',
  10.       require: 'true'
  11.   },
  12.   price: {
  13.       type: 'number',
  14.       min: 1
  15.   }
  16. });
  17.  
  18. // ---------- controller -----
  19. // ....
  20. postCreate: function (req, res) {
  21.     Book.create(req.body)
  22.       .then(() => res.redirect('/'))
  23.       .catch((err) => console.log(err));
  24.   },
  25.  
  26. /* ------ Mongo server log ---
  27.  ...
  28. 2019-04-11T10:21:17.725+0000 I NETWORK  [listener] connection accepted from 127.0.0.1:48586 #2 (1 connection now open)
  29. 2019-04-11T10:21:17.727+0000 I NETWORK  [conn2] received client metadata from 127.0.0.1:48586 conn2: { driver: { name: "nodejs", version: "3.2.2" }, os: { ... }, platform: "Node.js v6.11.2, LE, mongodb-core: 3.2.2" }
  30. */
Advertisement
Add Comment
Please, Sign In to add comment