![](/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.