I'm new to pymongo, MongoDB and mostly even Python 3, so please be kind if it's obvious.
I'm trying to backup a collection by copying it to another using $out. This and this question have seemingly useful and accepted answers on how it should work, but I couldn't get it to work the same way myself. Both answers say, after specifying the pipeline
pipeline = [ {"$match": {}},
{"$out": "destination_collection"},
]
you can use .aggregate like so
db.source_collection.aggregate(pipeline)
My code finally did work after I removed db. in the beginning and I'd like to understand why. My best guess is, that it has something to do with the fact that instead of using the collection name, I'm using a variable like so, according to a w³schools tutorial:
allData = dataBase["db_name"]
myData = allData["source_collection"]
Am I right, thinking that since what myData evaluates to, the example above doesn't work? Because it already contains the "db."-part of information? Since I had it from the tutorial, I thought it was the only way or at least "standard procedure", however it appears that it's not. How should I handle this in the future, any reasons to do it one way or the other?
Cheers, Morten