0

I have a document like below in mongo database and I have corresponding Model class Flight.java with all possible fields that are come in any time as update ?

{
    "flight": {
        "event": "Leg",
        "version": "2",
        "key": {
            "fltNum": "1111",
            "fltOrgDate": "2021-01-12",
            "depSta": "BBB",
            "dupDepStaNum": "0"
        },
        "leg": {
            "stations": {
                "arr": "VVV",
                "dupArrStaNum": "0"
            },
            "times": {
                "STD": "2021-01-12T20:30:00",
                "STA": "2021-01-12T23:21:00",
                "LTD": "2021-01-12T20:30:00",
                "LTA": "2021-01-12T23:05:00",
                "PTA": "2021-01-12T23:05:00"
            },
            "status": {
                "leg": " ",
                "dep": "S",
                "arr": "S"
            }
        }
    }
}

So I will get updates for this document continuously with existing fields or some new fields also. I am not sure which filed will get update.

So How can I update document using java MongoDB or Spring Data MongoDB?

1
  • Could you approve the answer if it was helpful? Commented Jan 18, 2021 at 16:52

1 Answer 1

0

Well, you have pojo which has all possible fields.

Every update requires three parts.

  1. Find command to identify the doc to be updated
  2. Doc which specifies what will be updated
  3. Options specifies upsert, multi

You can iterate each fields in pojo and check for not null fields then add it to updateDoc

example update in java

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.