Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

How to exclude some fields in a list of a document in a collection if the value in a field of list is equal to some value in mongodb using java?

I have a list in a document in mongodb, where I have field in list i.e., fieldName then I have hide the exclude entries in the list whose fieldName matching with the value I have give and return rest of the elements. I want some aggregation help in java.

{
    "personName": "Harry Potter",
    "personSearchId": {
        "$numberLong": "5"
    },
    "personId": {
        "$numberLong": "2"
    },
    "searchId": {
        "$numberLong": "223"
    },
    "modifiedBy": "Tom Cruise",
    "searchlist": [{
        "fieldName": "DELIVERY_STATUS",
        "label": "V_PENDING",
        "action": "UPDATED"
    }, {
        "fieldName": "UPLOADED_ON",
        "label": "Dec 8, 2020",
        "action": "UPDATED"
    }, {
        "fieldName": "RE_UPLOADED_ON",
        "label": "Jan 28, 2021",
        "action": "UPDATED"
    }, {
        "fieldName": "State",
        "label": "New South Wales",
        "action": "CREATED"
    }, {
        "fieldName": "Country",
        "label": "Australia",
        "action": "CREATED"
    }],
    "email": "[email protected]",
    "updatedOn": {
        "$date": "2021-01-28T07:10:37.140Z"
    }
}

So in the above case if I pass "DELIVERY_STATUS" then I should get everything except one entry in searchlist ie., whose fieldName value matches with DELIVERY_STATUS

question from:https://stackoverflow.com/questions/65938149/how-to-exclude-some-fields-in-a-list-of-a-document-in-a-collection-if-the-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...