代码之家  ›  专栏  ›  技术社区  ›  Chthonic Project

MongoDB中避免交换重复

  •  0
  • Chthonic Project  · 技术社区  · 6 年前

    我正在使用MongoDB数据库构建一个医疗应用程序,其中存储了药物信息。这个数据库中有一些集合,其中一个是用于药物相互作用的。提供给我的数据在 每种药物 基础。也就是说,如果 一个 是一种与 , C类 ,和 ,我拿到了那对 (A,B) , (A,C) ,和 (A,D) . 但是,在分析药物的输入数据时,我又得到了同样的信息 C类 ,和 (B,A)

    当然,相应的医疗信息是相同的(即。, 一个 一个 ).

    集合结构

    document 有三个字段: name1 , name2 ,和 description .

    当第一次创建集合并填充它时,是否有方法索引此集合以便 (name1, name2) (name2, name1) (因为他们都会有相同的 描述 )? 我不想在收藏中插入这样的副本。

    MongoDB Java Driver 3.8 使用MongoDB 4.0.3。

    {
        "_id" : ObjectId("5be9eaeedb9c7a2836cdd48c"),
        "name1" : "Lepirudin",
        "name2" : "St. John's Wort",
        "description" : "The metabolism of Lepirudin can be increased when combined with St. John's Wort."
    }
    

    我有一个升序索引 姓名2 以及上的文本索引 描述

    {
        "_id" : ObjectId("5be9eaeedb9c7a2836cdd49e"),
        "name1" : "St. John's Wort",
        "name2" : "Lepirudin",
        "description" : "The metabolism of Lepirudin can be increased when combined with St. John's Wort."
    }
    
    0 回复  |  直到 6 年前