node.js 在猫鼬中使用“修剪”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20766360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:33:53  来源:igfitidea点击:

What's the meaning of 'trim' when use in mongoose?

node.jsmongodbmongoosetrim

提问by Undefined Behavior

The link is http://mongoosejs.com/docs/api.html#schema_string_SchemaString-trim

链接是http://mongoosejs.com/docs/api.html#schema_string_SchemaString-trim

I'm beginner in mongoosejs. I just don't get it...

我是 mongoosejs 的初学者。我就是不明白...

I saw this question How to update mongoose default string schema property trim?but don't understand why trim. Im creating my first schema today like a 'hello world'.

我看到了这个问题How to update mongoose default string schema property trim? 但不明白为什么要修剪。我今天创建了我的第一个模式,就像一个“你好世界”。

I saw this to https://stackoverflow.com/tags/trim/info... but when i need to use it, i want to learn more about it. Im looking for an explanation for a beginner...

我在https://stackoverflow.com/tags/trim/info 上看到了这个……但是当我需要使用它时,我想了解更多关于它的信息。我正在为初学者寻找解释......

回答by Traveling Tech Guy

It's basically there to ensure the strings you save through the schema are properly trimmed. If you add { type: String, trim: true }to a field in your schema, then trying to save strings like " hello", or "hello ", or " hello ", would end up being saved as "hello"in Mongo - i.e. white spaces will be removed from both sides of the string.

它基本上可以确保您通过架构保存的字符串被正确修剪。如果您添加{ type: String, trim: true }到架构中的字段,那么尝试保存像" hello", or "hello ", or 之类的字符串" hello "最终会像"hello"在 Mongo中一样保存- 即将从字符串的两侧删除空格。

回答by Sachin

Using trim will help in removing the white spaces present (beginning and ending of the string) in the string that you want to save to the DB like

使用修剪将有助于删除要保存到数据库的字符串中存在的空格(字符串的开头和结尾),例如

"ABC " , "     ABC  ",

will be saved in the form

将保存在表单中

"ABC"

回答by Rahul

trim in mongoose use to remove the white spaces from the strings

猫鼬修剪用于从字符串中删除空格