【问题标题】:How I can find if string exists inside mongodb Array我如何找到字符串是否存在于 mongodb 数组中
【发布时间】:2022-06-16 19:05:38
【问题描述】:

我正在尝试根据 MongoDB 中的 profileID 查找文档。我想检查字符串 postid 是否存在于数组中。我怎么能这样做?我试过$all。

// Mongo data
{
  "profileId": "abc",
  "likedPosts": [
    'post1',
    'post2'
  ]
}

// Trying to find if post1 exists in array

findOne({
  profileId
}, {
  likedPosts: {
    $all: ['post1']
  }
}, )

【问题讨论】:

  • 你试过 $in 吗?

标签: javascript node.js mongodb


猜你喜欢
  • 1970-01-01
  • 2020-06-21
  • 1970-01-01
  • 2020-07-06
  • 1970-01-01
  • 2011-04-04
  • 1970-01-01
  • 2022-12-18
  • 1970-01-01
相关资源
最近更新 更多