收藏
回答

小程序云开发数据库怎么按照数组中对象的某个元素查询?

集合名:table,查询条件:buyTime='2020-04-29 14:15:05',上图中buyerInfo是一个数组,怎么根据buyTime查询出图中标红的这条数据?

回答关注问题邀请回答
收藏

8 个回答

  • 永远
    永远
    2021-08-02
    const command = db.command
    where({
    buyerInfo: command.elemMatch({buyTime: command.eq("2020-04-29 14:15:05")})
    })
    
    

    https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.elemMatch.html

    2021-08-02
    有用 5
    回复
  • HCL
    HCL
    2022-06-25

    return await db.collection(event.dbName).where({

                _openid: event._openid,

                "theoryRecruitRecord._id": event._id,

            }).field({

                "theoryRecruitRecord.$": true,

            }).get()

    2022-06-25
    有用 2
    回复 2
    • Cat
      Cat
      2022-12-12
      加了field({字段名.$: true})就行了
      2022-12-12
      回复
    • Cat
      Cat
      2022-12-12回复Cat
      楼主的方法可行
      2022-12-12
      回复
  • 禾店短剧系统
    禾店短剧系统
    2021-06-19

    请问这个问题解决了吗

    2021-06-19
    有用 1
    回复
  • Lee
    Lee
    2020-11-06

    https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-sdk-api/database/command/Command.elemMatch.html

    2020-11-06
    有用 1
    回复
  • 雷雪峰
    雷雪峰
    2020-04-30

    where({

    buyerInfo:{buyTime:'2020-04-29 14:15:05'}

    })

    2020-04-30
    有用 1
    回复 3
    • SOMETIMES
      SOMETIMES
      2020-04-30
      这样写全量返回呀,感觉筛选条件没起作用
      2020-04-30
      回复
    • 晴天ペ
      晴天ペ
      2020-11-25回复SOMETIMES
      解决了吗
      2020-11-25
      回复
    • 
      2020-12-22
      解决了吗
      2020-12-22
      回复
  • GGGGG
    GGGGG
    2022-05-24

    利用elementmatch 和regexp套用就行

    2022-05-24
    有用
    回复
  • 米艳明
    米艳明
    2020-11-22

    请问,这个问题解决了吗?上面列举的都不行啊

    2020-11-22
    有用
    回复
  • 2020-06-14

    这个问题解决没?

    2020-06-14
    有用
    回复
登录 后发表内容
问题标签