I am having a json file containing the following typ of data:
{"_id":{"$oid":"5913ff31cb98a111ec26c4be"},"email":"abc@example.com","src":[{"acc":"ln"},{"acc":"mysp"},{"acc":"beta","login":"seller","lang":"english"}]}
{"_id":{"$oid":"5913ff31cb98a111ec26c4bf"},"email":"francescoseccia@example.com","src":[{"acc":"ln"}]}
{"_id":{"$oid":"5913ff31cb98a111ec26c4c0"},"email":"paulcohenlaw@example.com","src":[{"acc":"ln"}]}
{"_id":{"$oid":"5913ff31cb98a111ec26c4c1"},"email":"david.martinez_01@example.com","src":[{"acc":"ln"}]}
{"_id":{"$oid":"5913ff31cb98a111ec26c4c2"},"email":"sodanoa@example.it","src":[{"acc":"ln"}]}
{"_id":{"$oid":"5913ff31cb98a111ec26c4c3"},"email":"boyhoxiy@example.com","src":[{"acc":"ln"}]}
{"_id":{"$oid":"5913ff31cb98a111ec26c4bf"},"email":"FRancescoseccia@example.com","src":[{"acc":"ln","login":"in"},{"acc":"mysp","login":"beta"},{"acc":"db","login":"beta"}]}
These are json values.
I am trying to insert the values in MongoDB using pymongo library. I want to insert the value in the following way:
{
"_id" : ObjectId("592402db50409d7e8d94fae4"),
"email" : "abc@example.com",
"src" : [
{
"acc" : "ln"
},
{
"acc" : "mysp"
},
{
"acc" : "beta"
}
],
"login" : [
"seller"
],
"lang" : [
"english"
]
}
{
"_id" : ObjectId("592402eb50409d7e8d94fae5"),
"email" : "francescoseccia@example.com",
"src" : [
{
"acc" : "ln"
}
]
}
{
"_id" : ObjectId("592402f850409d7e8d94fae6"),
"email" : "paulcohenlaw@example.com",
"src" : [
{
"acc" : "ln"
}
]
}
{
"_id" : ObjectId("5924030550409d7e8d94fae7"),
"email" : "david.martinez_01@example.com",
"src" : [
{
"acc" : "ln"
}
]
}
{
"_id" : ObjectId("5924031150409d7e8d94fae8"),
"email" : "sodanoa@example.it",
"src" : [
{
"acc" : "ln"
}
]
}
{
"_id" : ObjectId("5924031c50409d7e8d94fae9"),
"email" : "boyhoxiy@example.com",
"src" : [
{
"acc" : "ln"
}
]
}
{
"_id" : ObjectId("5924032850409d7e8d94faea"),
"email" : "FRancescoseccia@example.com",
"src" : [
{
"acc" : "ln"
},
{
"acc" : "mysp"
},
{
"acc" : "db"
}
],
"login" : [
"in",
"beta"
]
}
Just need to keep the acc' in the
src` set. And if there are any other values, that nee to be outside in the separate set.
Kindly, let me know who I can do that using pymongo.