【问题标题】:MongoDB Search for documents by passing parameters of an arrayMongoDB 通过传递数组的参数来搜索文档
【发布时间】:2020-09-06 09:24:54
【问题描述】:
Matches.find({
  user_one: [
    {
      user: userId,
      punctuation: { $gt: -1 },
    },
  ],
},

如果我运行这个查询,我不会得到预期的结果,但是,如果我运行另一个,我会找到它。

Matches.find({
  user_one: [
    {
      user: userId,
      punctuation: 0,
    },
  ],
},

无论标点符号如何,如何搜索“user_one”数组中的“user”等于 userId 的文档?

【问题讨论】:

    标签: arrays mongodb mongoose mongodb-query mongoose-schema


    【解决方案1】:

    这看起来不错。

    Matches.find({ 'user_one.user': userId })
    

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多