猫鼬查找方法不起作用

时间:2015-12-03 23:18:43

标签: node.js mongodb mongoose

编辑:已解决。它只是在if语句的末尾错过了一个括号。

感谢您的时间!

我使用Hotel.find的行似乎没有被执行,因此它下面的代码根本不起作用。我没有收到任何错误或警告。它只是没有做任何事情。我不明白我做错了什么。

function getPlaces() {

mongoose.connect("mongodb://localhost:27017/gtdb");
var db = mongoose.connection;

db.on("error", console.error.bind(console, "Connection error:"));
db.once("open", function(callback) {

//Define the hotel schema.
var Schema = mongoose.Schema;

var hotelSchema = new Schema({
  "PlaceName" : String,
  "PlaceType" : String,
  "PlaceAddress" : String,
  "Telephone" : String,
  "PlaceCity" : String,
  "ZipCode" : Number,
  "State" : String,
  "Country" : String,
  "EstimatedPrice" : Number,
  "PhotoUrl" : String,
  "OtherDetails" : String
 }); 

var Hotel = mongoose.model("Hotel", hotelSchema);

if (searchtype == "Hotel") {
  console.log("Request received for hotel data.");

  Hotel.find(function(err, hotels) { //This is the line it won't execute.
  var i;
    console.log(hotels);
    console.log("Find test");

  for (i = 0; i < hotels.length; i++) {
     dataarray[i] = hotels[i];
  }
 });

} else if (searchtype == "Event") {
    Event.find(function(err, events) {
 });
}

    mongoose.disconnect();

 }); //End of db.once function.
} //End of the getPlaces function.

感谢您的时间。

0 个答案:

没有答案