简体   繁体   English

要求或不要求猫鼬{模型,架构}?

[英]To require or not to require { model, Schema } for mongoose?

Is there any difference between requiring twice as opposed to just destructuring model and Schema from the existing variable mongoose already created?与从已经创建的现有变量mongoose解构modelSchema相比,需要两次有什么区别吗?

Here are the two different examples.这是两个不同的例子。 In a Node app is there a difference between the two following code examples outside of basic syntax and readability.在 Node 应用程序中,除了基本语法和可读性之外,以下两个代码示例之间是否存在差异。

const mongoose = require('mongoose');
const { model, Schema } = mongoose;
const mongoose = require('mongoose')
const { model, Schema } = require('mongoose')

It seems they both work fine.看起来他们都工作得很好。 I assume it's a very simple question to answer.我认为这是一个非常简单的问题。

If you need the mongoose object later, then go with the first one.如果您稍后需要mongoose对象,请使用第一个。 If you want to use only model and Schema then go simply with:如果您只想使用modelSchema那么只需使用:

const { model, Schema } = require('mongoose')

You don't want to load the module twice, there is a performance difference.您不想两次加载模块,这存在性能差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM