我需要將find()的查詢結(jié)果暴露給其他頁(yè)面,但是find()查詢操作是異步的,該如何實(shí)現(xiàn)呢?var settings = require ("./settings");var mongoose = require('mongoose');var db = mongoose.connection;var Schema = mongoose.Schema;mongoose.connect('mongodb://'+settings.host+'/'+settings.db);var articleSchema = new Schema({ title : String, author : Array, aclTitle : Array, creation : Array, brife : Array});var articleModel = mongoose.model('articles',articleSchema);var articleEntity = new articleModel({});db.on('error',function(){ console.log("連接出現(xiàn)錯(cuò)誤")});db.once('open',function () { console.log("連接成功!")});articleModel.find(function(e,d) { module.exports = d;//我這里想把查詢結(jié)果exports出去,另一個(gè)頁(yè)面require進(jìn)來}) //但是因?yàn)槭钱惒降?,寫在回調(diào)里,別的頁(yè)面require進(jìn)去是空對(duì)象, //寫在回調(diào)外面,那就取不到這個(gè)查詢結(jié)果
用mongoose查詢數(shù)據(jù)異步問題
慕工程0101907
2018-08-03 14:09:57