【问题标题】:MongoDB - find where BinData is equal to UUID valueMongoDB - 查找 BinData 等于 UUID 值的位置
【发布时间】:2018-10-05 09:49:41
【问题描述】:

我尝试用 Java 和 Spring Data MongoDB 编写应用程序。

我的文档看起来:

@Data
@ToString
public class SomeDocument {
    private UUID id;
    private String name;
}

存储库:

@Repository
public interface SomeDocumentMongoRepository extends MongoRepository<SomeDocument, UUID> {
}

这很简单。我保存了文档:

{
    "id": "5f4ac46b-55f7-4be4-b26f-2ca041334bec",
    "name": "some name"
}

然后我尝试使用简单的查询db.someDocument.find() 从数据库中读取它,我得到了结果:

{ "_id" : BinData(3,"5Ev3VWvESl/sSzNBoCxvsg=="), "name" : "some name", "_class" : "org.springmongodemo.repo.SomeDocument" }

所以我的问题是:

  1. 如何通过_id 使用给定的UUID 在mongo shell 文档中查找?
  2. BinData(3,...) 中的数字 3 是什么意思?

【问题讨论】:

标签: mongodb spring-data-mongodb


【解决方案1】:
  1. 要查找文档,您必须将 UUID 编码为 base64。 Please see this question.

  2. “3”是旧版 UUID 数据格式的标识符。更多信息请see here

如果您想从应用内查询,您应该使用 Spring Data 的功能,但从您的问题来看,我假设您想知道如何使用 mongo 本机工具进行查询。

【讨论】:

    猜你喜欢
    • 2013-04-13
    • 2021-09-03
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-18
    • 2015-06-08
    • 1970-01-01
    相关资源
    最近更新 更多