如何從通知中獲取僅通知 ID 的串列?物件是的notices子物件college。有一堆大學。從那里我想要一所大學的通知 ID 串列。
[
{
"_id": "6221b844b29fdd64c3e59045",
"admin": "6217bf38ba7d58a6fce43d05",
"name": "K S School of information technology",
"email": "[email protected]",
"phoneNo": "9283483",
"address": "gujarat university, navrangpura",
"city": "Ahmedabad",
"state": "Gujarat",
"zip": 132323,
"followers": 34,
"logo": "https://picsum.photos/500/300?img=1",
"imageList": [
{
"url": "https://picsum.photos/500/300?img=2",
"_id": "6221b8d8b29fdd64c3e590b0"
},
{
"url": "https://picsum.photos/500/300?img=3",
"_id": "6221b8ddb29fdd64c3e590bd"
}
],
"posts": [
{
"_id": "6221b844b29fdd64c3e5904b",
"likes": 23,
"url": "https://picsum.photos/500/300?img=1",
"likedUser": []
},
{
"_id": "6221b844b29fdd64c3e5904c",
"url": "https://picsum.photos/500/300?img=2",
"likedUser": [
"6217612917ddf1610fe905e8"
],
"likes": 1,
"isLiked": false
},
{
"likes": 0,
"url": "http://res.cloudinary.com/dofftzsmf/image/upload/v1646641956/My Uploads/ymnht6ob9mazepmkd2d1.png",
"caption": "I think this will work",
"_id": "6225c3b1dfe67efa88f7e048"
},
{
"url": "http://res.cloudinary.com/dofftzsmf/image/upload/v1646669123/My Uploads/rwtmcchpijczaslckmnv.png",
"caption": "hjhkjfdjdsfhjkfhdjksdfh",
"likes": 0,
"likedUser": [],
"_id": "62262d4cf4daaddffb02dd3f"
}
],
"notices": [
{
"noticeTitle": "New announcements",
"notice": [
{
"description": "New Notice ",
"noticeLink": "https://picsum.photos/500/300?img=1",
"_id": "6225d54895c2d6278941c421"
}
],
"_id": "6225d54895c2d6278941c420"
},
{
"noticeTitle": "New announcements",
"notice": [
{
"description": "New Notice ",
"noticeLink": "https://picsum.photos/500/300?img=1",
"_id": "6225e49c95c2d6278941caf4"
}
],
"_id": "6225e49c95c2d6278941caf3"
}
],
"aboutUs": [
{
"imageUrl": "http://res.cloudinary.com/dofftzsmf/image/upload/v1646652965/My Uploads/zcbihjc5yijjuqhfrmpc.png",
"title": "New Title (Updated!!)",
"description": "Now it is working Hello World",
"_id": "6221b844b29fdd64c3e59050"
},
{
"imageUrl": "https://picsum.photos/500/300?img=1",
"title": "Placement",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
"_id": "6221b844b29fdd64c3e59051"
}
],
"__v": 123
}
]
uj5u.com熱心網友回復:
mongodb中的投影一般有2個選項
- $project聚合 - 為此,您必須在管道中添加一個專案階段以及其他階段(如果有)。
db.college.aggregate([
{
'$project': {
'notices._id': 1
}
}
])
- 在查找選項中添加專案- 如果您有簡單的查詢或沒有查詢,最好只在查找中使用專案
db.college.find({your query}, {'notices._id':1})
uj5u.com熱心網友回復:
要僅獲取 Id,您必須首先使您的函式異步,并且在該異步函式內部您必須使用 await,而不是在 Model 中您必須應用您可以在Model.findById()中看到的過濾器屬性。
uj5u.com熱心網友回復:
db.college.find({},
{
"notices": {
"notice": {
"_id": 1
}
}
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/440283.html
