gpt4 book ai didi

从用户名 X 转发 Mongodb 查询

转载 作者:可可西里 更新时间:2023-11-01 10:30:51 27 4
gpt4 key购买 nike

我在 Mongo 查找结果时遇到了问题。示例如何从 _id X 开始查询转发示例我知道我有文档,其中有 1000 个用户的详细信息我知道列表中有一个名为 Peter 的用户我可以查询 Users.find({userName: "Peter"}) 并在用户上获取此信息_id 但是我如何才能在这之后获得所有用户而我需要从上面的“Peter”返回 JSON

最佳答案

根据您提供的少量信息,您需要分两步完成此操作:

获取第一个匹配名字“peter”的记录的id。

db.test.findOne({"userName":"Peter"},{"_id":1});

Returns one document that satisfies the specified query criteria. If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk. In capped collections, natural order is the same as insertion order.

一旦你有了 peter 的记录 ID,你就可以用它们的 ID > 这条记录的 ID 来检索记录。

db.test.find({"_id":{$gte:x}});

其中,x为第一次查询返回的第一条记录的id。

关于从用户名 X 转发 Mongodb 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25621851/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com