![](/img/trans.png)
[英]Searching one collection by a value in another, in Meteor (MongoDB)
[英]Meteor - Assigning a mongodb query to a variable and inserting it to another collection
如何将mongodb查询分配给变量并将其插入另一个集合? 我似乎无法弄清楚。
Meteor.methods({
'insertStatusData':function(statusInput,categorySelected,dateDB,userEmail,currentEventID){
var eventNameCol = Events.find({_id:currentEventID});
var eventName = eventNameCol.eventName; //trying to assign query to a variable
Status.insert({
currentEventName: eventName, //Inserting the query to a collection
statusDesc : statusInput,
category : categorySelected,
date: dateDB,
userEmail: userEmail,
eventID : currentEventID,
});
},
});
使用findOne()
方法返回与选择器匹配的第一个文档,而不是find()
方法将光标返回到集合中的文档(而不是与选择器匹配的实际文档),并且不立即访问数据库:
Meteor.methods({
'insertStatusData': function(statusInput,categorySelected, dateDB, userEmail, currentEventID){
var eventName = Events.findOne({_id: currentEventID}).eventName; //trying to assign query to a variable
Status.insert({
currentEventName: eventName, //Inserting the query to a collection
statusDesc : statusInput,
category : categorySelected,
date: dateDB,
userEmail: userEmail,
eventID : currentEventID,
});
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.