【问题标题】:CouchDB / PouchDB mango query: has in arrayCouchDB / PouchDB 芒果查询:有数组
【发布时间】:2021-12-21 21:35:20
【问题描述】:

芒果查询是否可以找到那些在数组字段中提供字符串的文档?

说,

const doc = {
  _id: 'testdoc',
  tags: ['pouch', 'couch', 'mysql'],
}

$db.find({ selector: {
  tags: {
    $has: 'pouch' // what goes here?
  } 
}})

【问题讨论】:

    标签: couchdb pouchdb


    【解决方案1】:

    你必须使用 $elemMatch 操作符

    {
      selector: {
        tags: {
          "$elemMatch": { $eq: "pouch" }
        }
      }
    }
    

    如需更多文档,请联系here

    【讨论】:

    • 非常感谢,我试试看。文档中这个运算符的定义让我很困惑,我决定它做相反的事情:)
    • 对我来说,这行得通tags: { $elemMatch: { $eq: 'pouch'} }
    猜你喜欢
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多