猫鼬 - 为什么我们制造“mongoose.Promise = global.Promise”设置猫鼬模块时? [英] Mongoose - Why we make "mongoose.Promise = global.Promise" when setting a mongoose module?

查看:76
本文介绍了猫鼬 - 为什么我们制造“mongoose.Promise = global.Promise”设置猫鼬模块时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在和Mongoose合作。我见过很多开发人员发出以下命令:

I'm working with Mongoose. I have seen a lot of developers make the following command:

mongoose.Promise = global.Promise;

然后我很想知道 mongoose.Promise的原始值是多少。我在编辑器中输入了以下命令:

Then I was curious to see what is the original value of mongoose.Promise . I have entered in my editor the following command:

const mongoose = require("mongoose");

console.log("promise: ", mongoose.Promise);

我的控制台退回了我:


承诺:函数Promise(){[native code]}

promise: function Promise() { [native code] }

好的,为什么要生成命令 mongoose.Promise = global.Promise 因为Mongoose的承诺已经返回本机代码?我不明白这一点,如果有人可以帮助我们理解,那就太棒了,

Okay, so why make the command mongoose.Promise = global.Promise since the Mongoose's promise already returns a native code ? I don't understand the point, if someone can help us to understand, would be great,

谢谢

推荐答案

这是Mongoose 5不需要的旧示例中的遗留代码。

This is legacy code from older examples that isn't needed with Mongoose 5.

Mongoose 4依赖于自己的promise实现, mpromise mongoose.Promise 不一定是承诺全球。

Mongoose 4 relied on its own promise implementation, mpromise. mongoose.Promise wasn't necessarily Promise global.

Mongoose 4文档指出:


默认情况下,Mongoose 5.0将使用本机承诺(或者如果本机承诺不存在,则为bluebird,
)但仍然需要插入自己的
支持ES6兼容的promises库。 Mongoose 5.0
不支持mpromise。

Mongoose 5.0 will use native promises by default (or bluebird, if native promises are not present) but still support plugging in your own ES6-compatible promises library. Mongoose 5.0 will not support mpromise.

虽然关于Bluebird的声明不再适用; Mongoose 5放弃了没有本机承诺的Node版本的支持。

Though the statement about Bluebird is no longer true; Mongoose 5 dropped the support of Node versions that don't have native promises.

mongoose.Promise = global.Promise;

如果 global.Promise ,可能仍需要

在导入Mongoose之后被分配了另一个实现(例如Bluebird),但更好的方法是更早地分配 global.Promise = Bluebird

这篇关于猫鼬 - 为什么我们制造“mongoose.Promise = global.Promise”设置猫鼬模块时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆