推荐工具
› RoboMongo
推荐书目
› 50 Tips and Tricks for MongoDB Developers
Related Blogs
› Snail in a Turtleneck
stargazer
V2EX  ›  MongoDB

请教在 mongo 中如何对一个列表字段的内容进行模糊查询?

  •  
  •   stargazer · May 29, 2015 · 5208 views
    This topic created in 4177 days ago, the information mentioned may be changed or developed.

    RT,请教各位大神,如何对一个list的字段内容进行模糊查询,thx

    6 replies  •  2015-05-30 10:28:29 +08:00
    cevincheung
    cevincheung
    May 30, 2015
    1
    只能用正则了
    kongkongyzt
    kongkongyzt
    May 30, 2015 via iPhone
    2
    同问
    cevincheung
    cevincheung
    May 30, 2015❤️1
    3
    @kongkongyzt
    @stargazer

    正则
    db.collection.find({field :/^A/})
    stargazer
    stargazer
    OP
    May 30, 2015
    4
    @cevincheung
    list的也是么?
    karloku
    karloku
    May 30, 2015 via iPhone❤️1
    5
    @stargazer Array也一样, mongo对Array字段搜索不加操作符的话就是匹配任一的元素

    但是正则查询只有固定字符串头的才能使用index, 这点和大部分sql的like是一样的. 需要完全模糊查询话还是下面几种方案
    1 用textIndex, 这个方便但是现在不支持中文
    2 把字段分词以后专门存一个新字段来索引
    3 用专门的搜索引擎
    stargazer
    stargazer
    OP
    May 30, 2015
    6
    @karloku thx我明白了,多谢~
    @cevincheung 多谢指点~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2724 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:20 · PVG 21:20 · LAX 05:20 · JFK 08:20
    ♥ Do have faith in what you're doing.