首页 > 解决方案 > MongoError:拓扑已关闭,请在创建新文档后连接

问题描述

我在猫鼬中执行某些任务时遇到困难,我有一个代码,在创建新实体后,我立即在另一个实体中进行选择,但是在进行此选择时遇到错误

MongoError:拓扑已关闭,请连接

保存后触发事件

if (this.emitter) {
    await this.emitter('pre_create', {entity});
}
let response = await this.entity_class.create(entity);
if (this.emitter) {
    await this.emitter('post_create', {entity: response});
}

从事件中的另一个集合中选择另一个实体

 this.cache.account = await this.account_repository.find_one({
    name: account_name
});

如您所见,我封装了猫鼬。

标签: javascriptmongodbmongoose

解决方案


推荐阅读