$http.post('/api/user/' + userid._id, {
posts: {body: 'hallooo'}
});
//没有工作......但是
$scope.deleteThing = function(thing) {
$http.delete('/api/things/' + thing._id);
};
工作正常。我想发布" body"进入数组并得到404错误 这是我的架构:
var UserSchema = new Schema({
name: String,
email: { type: String, lowercase: true },
role: {
type: String,
default: 'user'
},
hashedPassword: String,
provider: String,
salt: String,
facebook: {},
twitter: {},
google: {},
github: {},
posts: [{body: String}],
date: { type: Date, default: Date.now }
});
我该怎么办?
答案 0 :(得分:0)
假设您的index.js如下所示:
'use strict';
var express = require('express');
var controller = require('./user.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
module.exports = router;
$http.post('api/user/' + userid._id)
没有路线。如果您要更新用户,请使用$http.put('api/user/' + userid._id)
。
我还建议你为子文档定义一个模式" posts"。
类似的东西:
var PostSchema = new Schema({
body: String
});
var UserSchema = new Schema({
name: String,
email: { type: String, lowercase: true },
role: {
type: String,
default: 'user'
},
hashedPassword: String,
provider: String,
salt: String,
facebook: {},
twitter: {},
google: {},
github: {},
posts: [PostSchema],
date: { type: Date, default: Date.now }
});