How can I get list of only notice ids from the notices? The notices
object is the sub-object of the college
. I have tried so hard but got so far in the end it doesn't even matter:
[
{
"_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
}
]
CodePudding user response:
To get only Id you have to first make your function async and than inside of that async Function you have to use await and than in Model you have to apply filter property which you can see in Model.findById().
CodePudding user response:
db.college.find({},
{
"notices": {
"notice": {
"_id": 1
}
}
})