MongoDB查询返回空数组 [英] MongoDB Query Returns Empty Array
问题描述
正在运行一个基本的快速应用程序,该应用程序已连接到将近0.5 GB的MongoDB数据库...当我运行时:
Have a basic express app going that is connected to an almost .5 GB MongoDB Database...When I run:
router.get('/', function(req, res, next) {
medical_data.find({'State':'CT'}, function(err, data) {
console.log(data)
res.render('index');
});
});
我得到一个返回的空白数组:
I get a blank array returned:
[]
GET / 304 87.233 ms - -
GET /stylesheets/style.css 304 4.842 ms - -
这是我要查询的来自MongoLab的条目:
Here is the entry from MongoLab that I'm trying to query for:
{
"_id": {
"$oid": "5671dfafd7f6fdd02436682e"
},
"Street": "65 KANE ST",
"City": "WEST HARTFORD",
"State": "CT"
}
这是我的medical_data模型:
And here is my medical_data model:
var mongoose = require('mongoose');
var medical_data_schema = new mongoose.Schema({
Street: String,
City: String,
State: String
});
var medical_data = mongoose.model('medical_data', medical_data_schema);
// Make this available to our other files
module.exports = medical_data;
为什么我要找回空白数组?如果我运行 findOne
而不是 find
,我会在控制台中获得 null
Why am I getting a blank array back? If I run findOne
instead of find
I get null
in the console
我之前曾经运行过其他成功的全节点应用程序,但是没有一个拥有如此大的数据库,所以我认为这可能是超时问题?我不确定,任何帮助都会很棒.
I've run other succesfull node apps before but none with a database as big as this, so I think it might be a timeout issue? I'm not sure, any help would be amazing.
推荐答案
在现有数据库之上安装Mongoose模式可能很棘手.首先,猫鼬会通过使模型名称复数来确定集合名称;因此,在您的情况下,Mongoose将使用集合 medical_datas
,而我的猜测是它实际上称为 medical_data
.
Fitting a Mongoose schema on top of an existing database can be tricky. For one, Mongoose will determine the collection name by pluralizing the model name; so in your case, Mongoose will use the collection medical_datas
, and my guess is that it's actually called medical_data
.
您可以使用 collection
来指定用于架构的集合名称.代码> 选项:
You can specify the collection name to use for a schema by using the collection
option:
var medical_data_schema = new mongoose.Schema({
Street : String,
City : String,
State : String
}, { collection : 'medical_data' });
这篇关于MongoDB查询返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!