我正在尝试使用分页来排序和限制嵌入式数组,是否有可能使用MongoRepository做到这一点。以下是我的json,我正在尝试获取十大通知

{
  "id":"5d357ce265cb136751177aas",
  "notifications": [
    {
      "id": "5d357ce743cb133241177aaa",
      "owner": null,
      "itemId": "5d357ce743cb11254584abg",
      "type": null,
      "createdOn": "2019-07-22T03:41:05.428+00:00",
      "read": false
    },
    {
      "id": "5d357d2b43cb133241177aaf",
      "owner": null,
      "itemId": "5d35745243cb11256954abg",
      "type": null,
      "createdOn": "2019-07-22T03:41:14.367+00:00",
      "read": false
    }
  ]
}


我期望这样的输出

"notifications": [
    {
      "id": "5d357d2b43cb133241177aaf",
      "owner": null,
      "itemId": "5d35745243cb11256954abg",
      "type": null,
      "createdOn": "2019-07-22T03:41:14.367+00:00",
      "read": false
    },
    {
      "id": "5d357ce743cb133241177aaa",
      "owner": null,
      "itemId": "5d357ce743cb11254584abg",
      "type": null,
      "createdOn": "2019-07-22T03:41:05.428+00:00",
      "read": false
    }

  ]

最佳答案

这可能会有所帮助:

db.collection.update( { <query selector> }, { <update operator>: {
"array.$.field" : value } } )

10-05 23:08
查看更多