如何在mongodb中的db.runCommand中将集合名称作为变量传递

时间:2013-07-29 09:54:40

标签: python mongodb

在python中我使用聚合进行查询,我正在使用db.runCommand。问题是我想插入变量集合名称而不是其实际名称。 假设集合名称是xyz。

 collec = 'xyz'
 func_(collec)

现在在我正在使用的另一个文件中

 def func_(collection1):
     data = db.runCommand('aggregate', 'collection1', pipeline=pipe)

所以如何在这个db.runCommand

中使用这个collection1而不是xyz

1 个答案:

答案 0 :(得分:2)

你是说这个吗?

def func_(collection1):
    data = db.runCommand('aggregate', collection1, pipeline=pipe)