내 앱에서 사용자는 자신의 모든 알림을 삭제할 수 있습니다. 이벤트 핸들러로서 나는이 있습니다userId로 레코드 제거 허용되지 않음
Uncaught Error: Not permitted. Untrusted code may only remove documents by ID. [403]
이 내가 추가하는 것을 잊었다 권한인가, 아니면 일반적으로이 작업을 수행 할 수 없습니다 :
가 호출Template.clearNotifications.events({
'click .clear-notifications': function() {
Notifications.remove({userId: Meteor.user()._id});
}
});
,이 오류가 발생합니다 ? 그렇다면 사용자 알림을 삭제할 수있는 옵션은 무엇입니까?
이var notification = Notifications.findOne({userId:Meteor.userId()});
Notifications.remove({_id:notification._id})
설명 : 클라이언트에
The behavior of remove differs depending on whether it is called by trusted or untrusted code. Trusted code includes server code and method code. Untrusted code includes client-side code such as event handlers and a browser's JavaScript console.
Trusted code can use an arbitrary Mongo selector to find the documents to remove, and can remove more than one document at once by passing a selector that matches multiple documents. It bypasses any access control rules set up by allow and deny. The number of removed documents will be returned from remove if you don't pass a callback.
As a safety measure, if selector is omitted (or is undefined), no documents will be removed. Set selector to {} if you really want to remove all documents from your collection.
Untrusted code can only remove a single document at a time, specified by its _id. The document is removed only after checking any applicable allow and deny rules. The number of removed documents will be returned to the callback.
http://docs.meteor.com/#remove
감사합니다. Dave, 이것이 내가 찾고있는 것입니다. 그리고 클라이언트에서 제거하면 게시 된 것들만 제거된다는 것을 깨닫지 못했습니다! – John