在前端使用丑陋的 mongodb _ids [英] Working with ugly mongodb _ids on front end

查看:43
本文介绍了在前端使用丑陋的 mongodb _ids的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个有点主观的问题,但我对在客户端使用 mongodb _ids 有一些担忧.我最好将 s52ruf6wst 或 xR2ru286zjI 之类的东西用于 RESTful 资源并处理少量项目.

A kinda subjective question but I have a few concerns about working with mongodb _ids on client side. I would better use something like s52ruf6wst or xR2ru286zjI for RESTful resources and working with small collections of items.

1) 我开始依赖后端数据库的专有实现(_id 字段名称和实现).如果我坚持使用这个 _ids,以后很难替换后端数据库.

1) I'm starting to be dependent on proprietary implementation of backend database (_id field name and implementation). If I stick with this _ids it is harder to replace back-end db later.

2) 我有包含 mongo _ids 的巨大丑陋 URL(即使对于 REST 端点 - 我不喜欢它)

2) I've got huge ugly URLs containing mongo _ids (even for REST endpoints - I don't like it)

3) 对于黑客和好奇的用户"来说,使用哪个后端数据库是显而易见的.

3) For hackers and "curious users" it is become obvious which back-end db is used.

正如我所见,大多数 Web 应用程序都使用自己的约定来确定 ids、uid、uuids 的外观,我认为它看起来更专业(比使用 db 供应商直截了当的丑陋实现).

As I see most of web applications use their own conventions on how ids, uid, uuids should look like, and I would say to me it looks more professional (than using staightforward ugly implementation by db vendor).

所以问题是什么时候最好使用标准的 mongo _ids 并在后端和前端使用它们?可以做些什么来改善这种情况?

So the question is when it is good to use standard mongo _ids and use them across back and front ends? And what can be done to improve the situation?

推荐答案

什么时候使用标准的 mongo _ids

when it is good to use standard mongo _ids

总是.除非你根本不喜欢它.但是您的个人偏好与安全无关.Mongo 的对象 ID 并非本质上不如任何其他标识符类型(整数、UUID 等)安全

Always. Except when you simply don't like it. But your personal preferences have nothing to do with security. Mongo's object ids are not inherently less safe than any other identifier type (integer, UUID, etc.)

ObjectID 被设计为在您的集群中是唯一的,这非常重要,因为 mongodb 是一个分布式数据库.它还有一个很好的特性:值随时间单调增加.此属性可能对您有用,也可能没用.

ObjectID is designed to be unique across your cluster and this is very important, because mongodb is a distributed DB. It also has a nice property: values are monotonically increasing with time. This property may or may not be useful to you.

这篇关于在前端使用丑陋的 mongodb _ids的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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