邮递员工作,但提取不行。我究竟做错了什么?

时间:2018-07-23 14:29:22

标签: node.js mongodb express mongoose

我正在通过Express,Node和Mongoose的ScotchIO教程进行工作-我似乎无法通过fetch()

如果我在邮递员中提出请求,它可以正常工作-我可以在Mlab上看到记录更新:-

postman body

postman headers

但是,如果我在chrome中发出ValidationError: User validation failed POST请求(在此进行测试,直到我可以使其正常工作,然后我将移至React Native应用),我会得到一系列ValidatorError: Path(用户是我的架构,然后它会更加具体,例如is required. userName fetch('http://localhost:3001/api/users', { method: 'POST', headers: { "Content-Type": "application/x-www-form-urlencoded", }, body: { userName: 'IngleburtHumperdink', email: "Ingle@Humber.com", password: "mypw_blah" } }) 等)。

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
    userName: {
        type: String,
        required: true,
    },
    email: {
        type: String,
        required: true,
    },
    password: {
        type: String,
        required: true,
    }
});

module.exports = mongoose.model('User', UserSchema);

我的模式:

int[] a = new int[10] { 10, 34, 56, -150, -200, 49, 63, 108, -94, -84 };
int[] result = a.OrderByDescending(x => x).ToArray();
Console.WriteLine(result[0]+" + "+result[1]+" = "+(int)(result[0]+result[1]));

已更新:server.js

server.js

1 个答案:

答案 0 :(得分:0)

结果是我错过了body: JSON.stringify({ userName:'myUserName' })

所以你是对的@AlexBlex,因为我正在发送JSON,只需要json.stringify()即可将其转换。

经过测试并修复。非常感谢!