Hi, I have a function written with pymongo that will access a collection and retrieve all documents that has a specific field, and then I use a specific projection for that field.
Now I am doing that in a loop for all specific pairs of fields and projections.
What I’m trying to find out is if there is a way to “string queries” like this into just one call to the collection?
def readRawPlotData():
Methods = Collection.distinct("header.Method")
plotMethods = [method for method in Methods if method in constants.getPlotColumnsByMethod(method, keys=True)]
rawPlotData = []
for method in plotMethods:
project = {"_id":0,"header":1}
for plotColumn in constants.getPlotColumnsByMethod(method):
project["data."+plotColumn] = 1
methodData = Collection.find({"header.Method":method},project)
for data in methodData:
rawPlotData.append(dumps(data))
return rawPlotData