为什么mongodb包裹objectid('')到字符串

发布于 2025-01-24 12:59:39 字数 604 浏览 4 评论 0原文

MongoDB将字符串值与数据库中的ObjectID('')一起包装。

当我用端点提出帖子请求时,我会得到200个响应,并且看到了类型字符串的 creatorid 属性的正确值。

看起来这样: “在此处输入图像描述”

但是在MongoDB中,它可以保存如此:

为什么这样做?我可以关闭此选项吗?

我的其他ID属性(在1级上)是对象的唯一ID,并且会自动生成。两者都是类型字符串。

任何帮助将不胜感激!

Mongodb keeps wrapping a string value with ObjectId(' ') in the database.

when I make a POST request with my endpoint, I get a 200 response and I see the correct value for my creatorID property that is of type string.

it looks like this: enter image description here

but in MongoDB it is saved like this:
enter image description here

why is it doing that? and can I turn this option off?

my other Id property (on level 1) is the unique id of the object and it gets automatically generated. Both are of type string.

any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2025-01-31 12:59:39

它可以自动创建自己的独特定义,您可以关闭此功能。
有关更多详细信息

示例

 var subSchema = mongoose.Schema({
         createId: string;
        // subschema content..
    }, { _id : false });

  @Prop({_id:false})
  SubSchema: subschemaArray;

It can make its own unique definition automatically, you can turn this feature off.
for more detail

example :

 var subSchema = mongoose.Schema({
         createId: string;
        // subschema content..
    }, { _id : false });

or

  @Prop({_id:false})
  SubSchema: subschemaArray;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文