javascript - Mongoose query hangs after callback -


this must user error, have reduced example far can, , can't spot it.

here make simple query, calls callback result , no error. however, program hangs afterwards; never exits.

import mongoose "mongoose";  const someschema = new mongoose.schema({     name: string });  const m = mongoose.model("someschema", someschema);  mongoose.connect("mongodb://localhost", err => {     console.error("connection error", err);     m.find({}, (queryerror, result) => console.log("result:", result, "error:", queryerror)); }); 

result:

connection error undefined result: [ { _id: 55ffada74fb9958d13ec7c4b, name: 'asdf', __v: 0 } ] error: null 

(program hangs instead of exiting)

i'm sure i've overlooked basic, can't spot in guide, , juggling things around isn't helping. weird, have bunch of more complex mongoose models working elsewhere.

  • mongoose: ^4.0.5
  • babel-node: 5.8.20

your program stay open until close mongodb connection (however, not mean "hangs"). put mongoose.disconnect(); when you're finished , script quit.

mongoose.connect("mongodb://localhost", err => {     console.error("connection error", err); // todo better handle error     m.find({}, (queryerror, result) => {         console.log("result:", result, "error:", queryerror);         mongoose.disconnect();     }); }); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -