【发布时间】:2015-11-19 20:50:00
【问题描述】:
我在 nodejs 中编写了一个宁静的 api,大部分情况下都相当成功。我正在访问的 MongoDB 中有两个集合返回空字符串,并且恰好是唯一在其名称中包含大写字母的集合。当我使用 MongoClient 时,我可以很好地访问这些集合,所以我知道它不是一个过时的 mongodb 驱动程序。
一个例子是当我尝试访问一个名为 bulkBuds 的集合时
//bulkBuds model
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var BulkBudsSchema = new Schema({
sourceLicense: String,
quantity: Number,
strainName: String,
priceProfile: String
});
mongoose.model('bulkBuds', BulkBudsSchema);
控制器在查询中有一点多余的逻辑,但简单的查找也会返回一个空字符串。
//bulkBuds controller
var express = require('express'),
router = express.Router(),
mongoose = require('mongoose'),
BulkBuds = mongoose.model('bulkBuds'),
Friends = mongoose.model('Api'),
config = require('../../config/config'),
jwt = require('express-jwt');
module.exports = function (app) {
app.use('/api/bulkBuds/', router);
};
router.get('/:license', jwt({secret: config.secret}), function (req, res, next) {
if(!req.user.friend){
res.status(401);
}
Friends.findById(req.user.id, function(err, friend){
if(err) throw err;
if(!friend) res.send("friend does not exist");
if(req.user.username != friend.username) res.send("invalid user");
console.log(req.params.license);
console.log(BulkBuds.find({}));
BulkBuds.find({'storeLicense': req.params.license, 'availableForSale': true},
"sourceLicense quantity strainName priceProfile", function (err, bulkBuds) {
if (err) return next(err);
console.log(bulkBuds);
res.send(bulkBuds);
});
})
});
任何建议将不胜感激,谢谢。
【问题讨论】:
标签: node.js mongodb find capitalization empty-list