当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Mongo.Collection.update方法代码示例

本文整理汇总了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);
			});
		}
	},
开发者ID:djulls07,项目名称:projects-manager,代码行数:53,代码来源:tasks.ts

示例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;
}
开发者ID:djulls07,项目名称:projects-manager,代码行数:33,代码来源:my-files.ts

示例3: function

 declareWinners: function () {
     Players.update({ score: { $gt: 10 } },
         { $addToSet: { badges: "Winner" } },
         { multi: true });
 }
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:5,代码来源:meteor-tests.ts

示例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);
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:31,代码来源:meteor-tests.ts

示例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,
开发者ID:djulls07,项目名称:projects-manager,代码行数:32,代码来源:tasks.ts

示例6: function

 'tasks.setPrivate': function(taskId, setToPrivate) {
   let task = Tasks.findOne(taskId);
   Tasks.update(taskId, {
     $set: {private: setToPrivate}
   });
 }
开发者ID:RichardHwang886,项目名称:todo4,代码行数:6,代码来源:tasks.ts


注:本文中的meteor/mongo.Mongo.Collection.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。