有没有办法在没有mongodb的情况下创建像_id字符串这样的mongodb? [英] Is there any way to create mongodb like _id strings without mongodb?

查看:97
本文介绍了有没有办法在没有mongodb的情况下创建像_id字符串这样的mongodb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常喜欢mongodb生成的_ids的格式。主要是因为我可以从客户端提取数据,如日期。我打算使用另一个数据库,但仍然希望我的文档类型为_id。如何在不使用mongodb的情况下创建这些ID?

I really like the format of the _ids generated by mongodb. Mostly because I can pull data like the date out of them client side. I'm planning to use another database but still want that type of _id for my document. How can I create these ids without using mongodb?

谢谢!

推荐答案

对象ID通常由客户端生成,因此任何MongoDB驱动程序都会有代码来生成它们。

Object IDs are usually generated by the client, so any MongoDB driver would have code to generate them.

如果您正在寻找JavaScript,这里有一些代码来自MongoDB Node.js驱动程序:

If you're looking for JavaScript, here's some code from the MongoDB Node.js driver:

https://github.com/mongodb/js-bson/blob/1.0-branch/lib/bson/objectid.js

另一种更简单的解决方案:

And another, simpler solution:

https://github.com/justaprogrammer/ObjectId.js

这篇关于有没有办法在没有mongodb的情况下创建像_id字符串这样的mongodb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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