本文整理匯總了TypeScript中meteor/mongo.Mongo.Collection.deny方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Mongo.Collection.deny方法的具體用法?TypeScript Mongo.Collection.deny怎麽用?TypeScript Mongo.Collection.deny使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類meteor/mongo.Mongo.Collection
的用法示例。
在下文中一共展示了Mongo.Collection.deny方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
// can only change your own documents
return doc.owner === userId;
},
remove: function (userId: string, doc: iPost) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
Posts.deny({
update: function (userId: string, doc: iPost, fields: string[], modifier: any) {
// can't change owners
return doc.userId !== userId;
},
remove: function (userId: string, doc: iPost) {
// can't remove locked documents
return doc.locked;
},
fetch: ['locked'] // no need to fetch 'owner'
});
/**
* From Collections, cursor.forEach section
*/
var topPosts = Posts.find({}, { sort: { score: -1 }, limit: 5 });
var count = 0;
topPosts.forEach(function (post: { title: string }) {
console.log("Title of post " + count + ": " + post.title);
count += 1;
});
示例2: function
import {Mongo} from 'meteor/mongo';
import {ownsDocument} from '../../permissions'
import * as _ from 'lodash';
export let Codes = new Mongo.Collection('codes');
Codes.allow({
update: function(userId, post) { return ownsDocument(userId, post); },
remove: function(userId, post) { return ownsDocument(userId, post); }
});
Codes.deny({
update: function(userId, post, fieldNames) {
// may only edit the following two fields:
return (_.without(fieldNames, 'title', 'javascript').length > 0);
}
});
示例3: insert
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
// Declare the Mongo.Collection
export const Quotes = new Mongo.Collection('quotes');
// Deny the client direct access to the Collection
Quotes.deny({
insert() { return true },
update() { return true },
remove() { return true }
})
示例4: function
import {Mongo} from 'meteor/mongo';
import {ownsDocument} from '../../permissions'
export let Maps = new Mongo.Collection('maps');
import * as _ from 'lodash';
Maps.allow({
update: function(userId, post) { return ownsDocument(userId, post); },
remove: function(userId, post) { return ownsDocument(userId, post); }
});
Maps.deny({
update: function(userId, post, fieldNames) {
// may only edit the following two fields:
return (_.without(fieldNames, 'title', 'width', 'height', 'type_array', 'height_array', 'script_array', 'game_id').length > 0);
}
});