2015-07-10 98 views
0

我想比較使用Express的兩個字段。我已經盡力了,但我得到了錯誤。如何編寫查詢查詢來比較Express和MongoDB中的兩個字段?

我附上了我的架構,路由和控制器。這些是API調用,我想知道如何通過AngularJS $http.get方法的兩個字段。我附上我的AngularJS控制器的API調用也

模式:

var PromusageSchema = new Schema({ 

    StoreID: { 
     type: String, 
     default: '', 
     trim: true 
    }, 
    StoreName: { 
     type: String, 
     default: '', 
     trim: true 
    }, 
}); 

mongoose.model('Promusage', PromusageSchema); 

控制器

exports.promusageByEMAIL = function(req, res, next, id) { 
    Promusage.find({customer_Email:id}) 
     .populate('user', 'displayName') 
     .exec(function(err, promusage) { 
      if (err) return next(err); 

      if (!promusage) return next(new Error('Failed to load Promusage ' + id)); 
     req.promusage = promusage; 
     next(); 
    }); 
}; 

路線

app.route('/promusages1/:promusageEmail') 
    .get(promusages.read) 
    .put(promusages.update) 
    .delete(promusages.delete); 

    // Finish by binding the Promusage middleware 
app.param('promusageEmail', promusages.promusageByEMAIL); 

回答

1

如果你想將信息發送到一個API,你應該使用$http.post或類似的。 $http.get用於檢索數據,而不是發送數據。

這就是說,它看起來像你實際上試圖從API獲取信息。但是,您的GET請求似乎沒有映射到可用的功能。應該是這樣的:.get(promusages.read)這是你的路線中的.get(promusages.find)

這是您定義的唯一功能。雖然很難說,因爲我不確定Promusage在這裏。