I need to insert a field in existing collection in mongodb at particular order. For e.g. If I have collection which contains document as:
item:{
//mandatory field, will exist in each document
id: "1",
//non-mandatory fields, may or may not exist in each document
name: "john",
age: "22",
email:"john@gmail.com" ,
}
Now I want to insert a field "gender" after age and before email so that my document becomes:
item:{
id: "1",
name: "john",
age: "22",
gender: "male",
email:"john@gmail.com"
}
My collections is basically of a POJO generated from xsd, A document may or may not contain certain fields. Therefore I can't just override the json.