These are chat archives for Automattic/mongoose

20th
Apr 2015
Maksim
@chetverikov
Apr 20 2015 05:09
@christiannwamba Hi! Don't understand your problem... Why you can't do Todo.create(req.body); ?
@demonicpagan What do you have the content in req.body?
app.post('/api/posts', function (req, res, next) {

        console.log(req.body);  //req.body?

        var post = new Post({
                username: req.body.username,
                body: req.body.body
        })

        post.save(function (err, post) {
                if (err) { return next(err) }
                res.json(201, post)
        })
})
Dustin Lennon
@dustin-lennon
Apr 20 2015 12:09
@chetverikov it is in what I posted as the cURL: curl -v -H "Content-Type: application/json" -XPOST --data "{\"username\":\"demonicp_eorzea\", \"body\":\"node rules!\"}" localhost:3000/api/posts. So in this case req.body would be - node rules!
Maksim
@chetverikov
Apr 20 2015 13:04
@demonicpagan I think you have a problem in req.body, not mongoose. Maybe wrong parsed json.
Dustin Lennon
@dustin-lennon
Apr 20 2015 13:05
@chetverikov explain how that is so for the wrong parsed json. I'm a bit lost on that.
Maksim
@chetverikov
Apr 20 2015 13:07
By the way, what version of mongoose you?
Dustin Lennon
@dustin-lennon
Apr 20 2015 13:08
I am running 4.0.1 of mongoose
Maksim
@chetverikov
Apr 20 2015 13:09
app.post('/api/posts', function (req, res, next) {
        var post = new Post({
                username: req.body.username,
                body: req.body.body
        })

        post.save(function (err, post) {
                if (err) { 
console.log(err);
                   return next(err)
 }
                res.json(201, post)
        })
})
What fields in the error you have is not correct?
err.errors ?
Dustin Lennon
@dustin-lennon
Apr 20 2015 13:14
Ok, I'm seeing the issue now. Somewhere I have a typo of what I'm trying to send. Path 'usernme' is required. I am feeling stupid now >.<
Maksim
@chetverikov
Apr 20 2015 13:15
hohoho. all right!