本文整理汇总了TypeScript中meteor/mongo.Mongo.Collection.insert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Mongo.Collection.insert方法的具体用法?TypeScript Mongo.Collection.insert怎么用?TypeScript Mongo.Collection.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meteor/mongo.Mongo.Collection
的用法示例。
在下文中一共展示了Mongo.Collection.insert方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: recordEvent
export function recordEvent(charId: number, text: string) {
EventLog.insert({
text: text,
time: new Date(),
charid: charId,
});
}
示例2: function
'tasks.addTask': function(text) {
Tasks.insert({
text: text,
checked: false,
private: false
});
},
示例3: function
'tasks.addTask': function(text: string) {
Tasks.insert({
text: text,
checked: false,
private: false,
createdAt: new Date()
});
},
示例4: addAction
function addAction(action:GamePlayAction, userId:string):string {
if (action.creatorId !== userId)
throw new Meteor.Error('invalid-user', 'current userId does not match user ID of passed object');
checkUser(action.gameId, action.creatorId);
action.cardsEncoded = CardEncoder.encodeCards(action.cards);
if (action.gameConfig) {
action.gameConfig._deck_id = action.gameConfig.deck.id;
} else {
}
return GamePlayActionCollection.insert(action);
}
示例5: function
addProject: function (name: string) {
check(name, String);
let user = Meteor.user();
if (!user || user.emails[0].address !== 'djulls07@gmail.com') {
throw new Meteor.Error('not-authorized');
}
let project = {
name: name,
owner: user._id,
ownerEmail: user.emails[0].address,
createdAt: new Date(),
users: [{ userId: user._id, email: user.emails[0].address }],
groups: []
}
let id = Projects.insert(project);
console.log('project saved: ', id);
},
示例6:
Meteor.startup(function () {
if (Rooms.find().count() === 0) {
Rooms.insert({ name: "Initial room" });
}
});
示例7: function
addTask: function(task: Task, notifyTargets: boolean, parentTaskId?: string) {
check(task.project, String);
check(task.name, String);
check(task.priority, String);
check(task.dueDate, Date);
check(task.description, String);
check(notifyTargets, Boolean);
let parentTask = null;
let project = Projects.findOne(task.project);
let isSubTask = false;
if (!project) {
throw new Meteor.Error('404', 'project-not-found');
}
if (parentTaskId) {
parentTask = Tasks.findOne(parentTaskId);
if (!parentTask) {
throw new Meteor.Error('404', 'parent-task-not-found');
}
isSubTask = true;
}
if (!task.targets || task.targets.length === 0) {
throw new Meteor.Error('400', 'Please select at least one target');
}
// verif et retrait des doublons targets
let targets = [];
let ids = {};
task.targets.forEach((target) => {
if (ids[target.userId] === true) return;
targets.push(target);
ids[target.userId] = true;
});
task.targets = targets;
let user = Meteor.user();
task.owner = user._id;
task.ownerEmail = user.emails[0].address;
task.createdAt = new Date();
task.validated = false;
task.archived = false;
task.completed = false;
task.conversation = [];
task.isSubTask = isSubTask;
task.hasSubTasks = false;
task.subTasks = [];
task.parentTask = parentTaskId || null;
let taskId = Tasks.insert(task);
let linking = linkFilesModel(project._id, 'task', taskId, task.files);
if (!linking) {
Tasks.remove(taskId);
throw new Meteor.Error('403', 'No more space for files');
}
// update parent task if needed
if (parentTaskId) {
Tasks.update(parentTaskId, {
$push: {
subTasks: taskId
},
$set: {
hasSubTasks: true
}
});
}
// si server et param notify == true:
this.unblock();
if (Meteor.isServer && notifyTargets) {
// send email to targets
task.targets.forEach((target) => {
let to = target.email;
Email.send({
to: to,
from: process.env.MAIL_FROM,
subject: 'You have a new task',
text: 'New task ['+task.name+'] on project: '+project.name+', added by ' + task.ownerEmail
});
});
}
console.log('Task saved: ', taskId);
return taskId;
},
示例8: check
return !!user;
}
});
Meteor.methods({
// Insert Task
'tasks.insert' (task) {
check(task.name, String);
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);
},
示例9: tasksPublication
import {Mongo} from 'meteor/mongo';
export let Test = new Mongo.Collection('test');
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('test', function tasksPublication() {
return Test.find();
});
}
Meteor.methods({
'test.get' () {
return Test.find().fetch();
},
'test.insert' () {
return Test.insert({title: "buhu", body: "this is the body"});
},
});