This router get function is entered, the log statement is printed to the console, but the find statement doesn't seem to be executing. Any obvious reasons?
const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');
const Product = require('../models/product');
module.exports = router;
const url = "mongodb://xxxx@ds027425.mlab.com:xxxx/xxxx";
mongoose.Promise = global.Promise;
mongoose.createConnection(url, function(err) {
if(err) {
console.log('Error!!!' + err);
} else {
console.log('Connected to Database!');
}
});
router.get('/product/specialvalue', function(req, res) {
console.log('Get specialvalue called xxxx');
Product.find({'special_value': true})
.sort({'price': 1})
.exec(function(err, products) {
if(err) {
console.error('Error retrieving special value products!');
res.json(err);
} else {
console.log("products = " + JSON.stringify(products));
res.json(products);
}
});
});
This is the Mongoose Model:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ProductSchema = new Schema({
producttype: String,
name: String,
brand: String,
model: String,
price: Number,
list_price: Number,
description: String,
rating: Number,
Continuation of the model: (The system is compelling me to add more detail)
item_no: String,
special_value: Boolean,
warranty: String,
feature: [String],
image: [String],
Continuation of the model:
specification: {
lowes_exclusive : Boolean,
color : String,
high_efficiency : Boolean,
automatic_load_balancing : Boolean,
product_capacity : String,
large_items_cycle : Boolean,
Continuation of the model:
exclusive_cycle : String,
maximum_spin_speed : String,
water_levels : String,
number_of_rinse_cycles : String
}
});
Continuation of the model:
var Product = mongoose.model('Product', ProductSchema, 'product');
module.exports=Product;