チェックリストを使用して、コレクションから場所を選択し、ToDelete:[{_id:String}]という配列に格納しようとしています。その配列では、Collectionsオブジェクトの内部の場所に対して実行して削除したいと考えています。ToDeleteItemの配列を使用して複数のネストされたオブジェクトを削除する方法
私はCollection IDを配列として、ボディとして格納します。私はそれがIDを持っていることを知っているので、コンソールにログを記録していますので、削除して正しくサービスに渡します。
私のサーバー側の機能は、どのようにモンゴーズのように見えるのですか?これは私の最高の試みです。ここで
//DELETE COLLECTION LOCATIONS
collectionRouter.post('removeLocation/:id', function(req, res, next) {
Collection.update(
{_id: req.params.id},
{$pull: {locations: {_id: {$in:req.body}}}},
function (err, result) {
if (err) {
return res.status(500).json({
title: 'An error occured',
error: err
});
}
res.status(201).json({
message: 'Locations Removed',
obj: result
});
});
});
私Collection.Serviceは
removeCollectionLocation(collection: Collection, locations: string[]) {
let body = locations;
const headers = new Headers({
'Content-Type': 'application/json'});
const token = localStorage.getItem('token')
? '?token=' + localStorage.getItem('token')
: '';
return this.http.post('http://localhost:3000/collection/removeLocation/' + collection._id + token , body, {headers: headers})
.map((response: Response)=> response.json())
.catch((error: Response)=> Observable.throw(error.json()));
}
であるあなたにみんなありがとう。
これは、okieである上記の機能に何の問題を観察していません。 – hardy
:( main.bundle.js:576例外TypeError:error.jsonはCatchSubscriber.selector で機能 ではありません、それはコードの私が提供した –
イエスのいずれでもない200のコードを返しますが、あなたが応答を使用することができます.json({isSuccess:false、err:err})あなたの関数をクラッシュさせずにエラー部分をログに記録する – hardy