在MongoDB中自动递增以存储唯一用户ID的序列

编程入门 行业动态 更新时间:2024-10-13 22:19:55
本文介绍了在MongoDB中自动递增以存储唯一用户ID的序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在制作一个分析系统,该API调用将提供一个唯一的用户ID,但顺序不正确且稀疏.

I am making a analytics system, the API call would provide a Unique User ID, but it's not in sequence and too sparse.

我需要给每个唯一用户ID一个自动增量ID,以在位阵列/位集中标记分析数据点.因此,第一个用户遇到的将对应于位数组的第一位,第二个用户遇到的将是位数组中的第二位,依此类推.

I need to give each Unique User ID an auto increment id to mark a analytics datapoint in a bitarray/bitset. So the first user encounters would corresponding to the first bit of the bitarray, second user would be the second bit in the bitarray, etc.

那么在MongoDB中是否有可靠且快速的方法来生成增量的唯一用户ID?

So is there a solid and fast way to generate incremental Unique User IDs in MongoDB?

推荐答案

可以,但不能 web.archive/web/20151009224806/docs.mongodb/manual/tutorial/create-an-auto-incrementing-field/

mongo中的每个对象都已经有一个ID,并且可以按插入顺序对其进行排序.获取用户对象集合,对其进行迭代并将其用作增量ID有什么问题?完全去从事地图减少工作

Each object in mongo already has an id, and they are sortable in insertion order. What is wrong with getting collection of user objects, iterating over it and use this as incremented ID? Er go for kind of map-reduce job entirely

更多推荐

在MongoDB中自动递增以存储唯一用户ID的序列

本文发布于:2023-11-28 15:10:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642907.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列   用户   MongoDB   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!