查找具有多字段的对象是否包含字符串

时间:2016-10-27 11:27:46

标签: mongodb find mongodb-query full-text-indexing

{
    "_id" : ObjectId("5811b03d231d884982672ddd"),
    "person-name" : "Bell, Lee Phillip",
    "info" : {
        "trivia" : [
            "Mother-in-law of 'Colleen Bell (II)' (qv) and 'Maria Arena Bell' (qv).",
            "Mother of actress 'Lauralee Bell' (qv), writer/producer 'Bradley Bell (I)' (qv) and TV executive 'William J. Bell Jr.' (qv)."
        ],
        "birthnotes" : [
            "Chicago, Illinois, USA"
        ],
        "spouse" : [
            "'William J. Bell' (qv) (October 1954 - 29 April 2005) (his death); 3 children"
        ],
        "birthname" : [
            "Phillip, Lee"
        ]
    }
}

我想在包含“Opera”的字段“info”中找到。有没有人有想法?

1 个答案:

答案 0 :(得分:0)

db.collection.ensureIndex({ "$**": "text" })
db.collection.find( { 
                      $text: { 
                               $search: "Opera",
                               $caseSensitive: true
                             }
                    }
);

使用mongo中的文本索引