本文整理汇总了TypeScript中meteor/mongo.Mongo.Collection.update方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Mongo.Collection.update方法的具体用法?TypeScript Mongo.Collection.update怎么用?TypeScript Mongo.Collection.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meteor/mongo.Mongo.Collection
的用法示例。
在下文中一共展示了Mongo.Collection.update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
archiveTask: function (taskId: string, compt?: number) {
check(taskId, String);
let c = compt || 0;
let user = Meteor.user();
let task = Tasks.findOne(taskId);
let auth = false;
if (!user || !task) {
throw new Meteor.Error('not-authorized');
}
let project = Projects.findOne(task.project);
if (!project) {
throw new Meteor.Error('404', 'project-not-found');
}
if (task.owner === user._id) {
auth = true;
}
if (user._id === project.owner) {
auth = true;
}
if (!auth) {
throw new Meteor.Error('not-authorized');
}
Tasks.update(taskId, {
$set: {
archived: true,
archivor: user._id
}
});
if (task.hasSubTasks) {
// on update et complete les sub tasks (qui ne le sont pas uniquement).
Tasks.update(
{
parentTask: task._id,
archived: false,
},
{
$set: {
archivor: user._id,
archived: true
}
},
{
multi: true
}
);
if (c >= 100) {
throw new Meteor.Error('500', 'too-many-rec');
}
task.subTasks.forEach((subTaskId) => {
Meteor.call('archiveTask', subTaskId, c+1);
});
}
},
示例2: linkFilesModel
export function linkFilesModel(projectId: string, modelName: string, modelId: string, filesIds: Array<string>) {
let ret = true;
// check if has right to upload more files for the projectId
let files = MyFiles.find({ $or: [{ projectId: projectId }, { _id: { $in: filesIds } }] });
let size = 0;
files.forEach((file) => {
size += file.size;
});
if (size > process.env.FILES_SIZE_PROJECT) {
console.log('No space anymore', size + ' > ' + process.env.FILES_SIZE_PROJECT);
ret = false; // not linking files will result in their removing
}
if (ret) {
console.log('files ids', filesIds);
MyFiles.update(
{
_id: { $in: filesIds }
},
{
$set: {
modelName: modelName,
modelId: modelId,
projectId: projectId
}
},
{
multi: true
}
);
}
return ret;
}
示例3: function
declareWinners: function () {
Players.update({ score: { $gt: 10 } },
{ $addToSet: { badges: "Winner" } },
{ multi: true });
}
示例4: assert
// DA: I added the "var" keyword in there
interface ChatroomsDAO {
_id?: string;
}
interface MessagesDAO {
_id?: string;
}
var Chatrooms = new Mongo.Collection<ChatroomsDAO>("chatrooms");
Messages = new Mongo.Collection<MessagesDAO>("messages");
var myMessages: any[] = Messages.find({ userId: Session.get('myUserId') }).fetch();
Messages.insert({ text: "Hello, world!" });
Messages.update(myMessages[0]._id, { $set: { important: true } });
var Posts = new Mongo.Collection("posts");
Posts.insert({ title: "Hello world", body: "First post" });
// Couldn't find assert() in the meteor docs
//assert(Posts.find().count() === 1);
/**
* Todo: couldn't figure out how to make this next line work with Typescript
* since there is already a Collection constructor with a different signature
*
var Scratchpad = new Mongo.Collection;
for (var i = 0; i < 10; i++)
Scratchpad.insert({number: i * 2});
assert(Scratchpad.find({number: {$lt: 9}}).count() === 5);
示例5:
let task = Tasks.findOne(taskId);
let c = compt || 0;
if (!user || !task) {
throw new Meteor.Error('not-authorized');
}
let project = Projects.findOne(task.project);
if (!project) {
throw new Meteor.Error('404', 'project-not-found');
}
if (task.owner !== user._id && project.owner !== user._id) {
throw new Meteor.Error('403', 'not-authorized');
}
Tasks.update(taskId, {
$set: {
validated: true,
completed: true,
completor: user._id,
validator: user._id
}
});
if (task.hasSubTasks) {
// on update et valide/complete les sub tasks (qui ne le sont pas uniquement).
Tasks.update(
{
parentTask: task._id,
validated: false,
completed: false
},
{
$set: {
validated: true,
completed: true,
示例6: function
'tasks.setPrivate': function(taskId, setToPrivate) {
let task = Tasks.findOne(taskId);
Tasks.update(taskId, {
$set: {private: setToPrivate}
});
}