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 - -
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"
}
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;
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.
Use BsonNull. Value with the MongoDB C# driver to query for null or missing fields in MongoDB.
Definition. $elemMatch. The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria.
In your case you could try: Person. find({ members: { $elemMatch: { id: id1 } } });
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
.
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' });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With