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


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

本文整理汇总了TypeScript中meteor/mongo.Mongo.Collection.findOne方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Mongo.Collection.findOne方法的具体用法?TypeScript Mongo.Collection.findOne怎么用?TypeScript Mongo.Collection.findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在meteor/mongo.Mongo.Collection的用法示例。


在下文中一共展示了Mongo.Collection.findOne方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:

Tracker.autorun(function () {
    var oldest = Monkeys.findOne('age = 20');

    if (oldest)
        Session.set("oldest", oldest.name);
});
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:6,代码来源:meteor-tests.ts

示例3: function

interface AnimalDAO {
    _id?: string;
    name: string;
    sound: string;
    makeNoise?: () => void;
}

// Define a Collection that uses Animal as its document
var Animals = new Mongo.Collection<AnimalDAO>("Animals", {
    transform: function (doc: any): Animal { return new Animal(doc); }
});

// Create an Animal and call its makeNoise method
Animals.insert({ name: "raptor", sound: "roar" });
Animals.findOne({ name: "raptor" }).makeNoise(); // prints "roar"

/**
 * From Collections, Collection.insert section
 */
// DA: I added the variable declaration statements to make this work
var Lists = new Mongo.Collection('Lists');
var Items = new Mongo.Collection('Lists');

var groceriesId = Lists.insert({ name: "Groceries" });
Items.insert({ list: groceriesId, name: "Watercress" });
Items.insert({ list: groceriesId, name: "Persimmons" });

/**
 * From Collections, collection.update section
 */
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:30,代码来源:meteor-tests.ts

示例4: function

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

示例5: Date

		}
		Tasks.update(taskId, {
			$push: {
				conversation: {
					message: message,
					createdAt: new Date(),
					owner: user._id,
					ownerEmail: user.emails[0].address
				}
			}
		});
	},
	validTask(taskId: string, compt?: number) {
		check(taskId, String);
		let user = Meteor.user();
		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,
开发者ID:djulls07,项目名称:projects-manager,代码行数:31,代码来源:tasks.ts

示例6: check

    check(task.status,String);
    // Make sure the user is logged in before inserting a task
    if (!Meteor.userId()) {
      throw new Meteor.Error('not-authorized');
    }
    Tasks.insert({
      name:task.name,
      status:task.status,
      owner: Meteor.userId(),
      created:new Date()
    });
  },
  'tasks.remove' (taskId) {
    console.log('removing tasks from collection');
    check(taskId, String);
	const task = Tasks.findOne(taskId);
    //if (task.private && task.owner !== Meteor.userId()) {
		//changed when got error in test...
	if (task.owner !== Meteor.userId()) {
      // If the task is private, make sure only the owner can delete it
      throw new Meteor.Error('not-authorized');
    }
    Tasks.remove(taskId);
  },
  'tasks.setStatus' (taskId, status) {
    check(taskId, String);
    check(status, String);
	const task = Tasks.findOne(taskId);
    //if (task.private && task.owner !== Meteor.userId()) {
	if (task.owner !== Meteor.userId()) {
      // If the task is private, make sure only the owner can check it off
开发者ID:LIOSK-ORG,项目名称:todo-app,代码行数:31,代码来源:tasks.ts

示例7: function

	addUserProject: function(projectId: string, userEmail: string) {
		let hasCreateUser = false;
		if (Meteor.isServer) {
			check(userEmail, String);
			check(projectId, String);

			let project = Projects.findOne(projectId);
			let user = Meteor.user();
			
			let pass = Random.id(8);

			if (!user || !project) {
				throw new Meteor.Error('403', 'not-authorized');
			}
			if (user._id !== project.owner) {
				throw new Meteor.Error('403', 'not-authorized');
			}

			let userAdd = Meteor.users.findOne({ 'emails.0.address': userEmail });
			if (!userAdd) {
				let userId = Accounts.createUser({ email: userEmail, password: pass });
				userAdd = Meteor.users.findOne(userId);
				if (!userAdd) {
					throw new Meteor.Error('404', 'user-not-found');
				}
				hasCreateUser = true;
			}
			let isIn = false;
			project.users.forEach((userP) => {
				if (userP.userId === userAdd._id) {
					isIn = true;
				}
			});
			if (!isIn) {
				Projects.update(projectId, {
					$push: {
						users: {
							email: userEmail,
							userId: userAdd._id
						}
					}
				});
			}
			this.unblock();
			if (Meteor.isServer && hasCreateUser) {
				// send email with password of account created.
				// send the pass to the creator email ( not the invited user ( avoid spam ))
				let to = user.emails[0].address
				Email.send({
					to: to,
					from: process.env.MAIL_FROM,
					subject: 'New user account created & invited',
					text: 	
						'You have invited a new user: "'+userEmail+'", his account has been created for you.\n'+
						'Please give the your new collaborator his credentials: \n\n'+
						'Login: ' + userEmail+'\n'+
						'Password: ' + pass
				});
			}
		}
		return { hasCreateUser: hasCreateUser };
	},
开发者ID:djulls07,项目名称:projects-manager,代码行数:62,代码来源:projects.ts


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