I am using pymongo to update some data in a mongodb. I am trying to use aggregate and lookup to combine data from two collections into one. Basically I am trying to do something like this: https://stackoverflow.com/a/35948843
Here is my code:
client = pymongo.MongoClient('localhost', 27017) #Connecting to mongo
db = client['<Database name>']
collection = db["<Collection name 1>"]
collection.aggregate([{
"$lookup": {
"from": "<Collection name 2>",
"localField": "Symbol",
"foreignField": "Symbol",
"as": "Extra Info"
}
}])
While I am not getting any error, I see that my collection has not been updated and the aggregation hasn't worked
I tried to output the result of the aggregation to check if there's any error:
results = collection.aggregate([{
"$lookup": {
"from": "<Collection name 2>",
"localField": "Symbol",
"foreignField": "Symbol",
"as": "Extra Info"
}
}])
print (list(results))
The output of the "results" comes out to be exactly what I want which means the aggregation has worked.
So I am trying to understand what I am doing wrong or stupid? If anyone could help that would be really helpful.