Tuesday 6 June 2017

Saving data in MongoDB in wrong order

Nodejs app with Express and MongoDB. I have form to insert title, author and body. After submitting data I noticed that instead of title, author and body it looks like body, author and title. So, I wonder is this order important in MongoDB? And why it switch positions. Image shows how it should be and what i got.

Code fragments (mongoose schema, pug view, main):

// article schema
let articleSchema = new Schema({
    title: String,
    author: String,
    body: String
})

  label Title:
  input.form-control(name='title', type='text')
#form-group
  label Author:
  input.form-control(name='author', type='text')
#form-group
  label Body:
  textarea.form-control(name='body')

article.title = req.body.title
article.author = req.body.author
article.body = req.body.body

P.S. App working only confusing order in DB.



via BlackB0ne

No comments:

Post a Comment