如何使用变量作为集合在MongoDB中查找文档?

时间:2016-01-15 10:06:39

标签: mongodb variables find pymongo

我想使用以下命令:

coll = sys.argv[1]
docs = db.coll.find()

这不起作用。如果我像这样硬编码就可以了:

docs = db.collection_I_want_to_query.find()

我猜find-function不起作用,因为coll是一个字符串。但是有可能使用变量进行查询吗?

1 个答案:

答案 0 :(得分:3)

http://api.mongodb.org/python/current/tutorial.html#getting-a-database

private int a;
private AutoResetEvent newResult = new AutoResetEvent(false);

private void ThreadA()
{
    while (true)
    {
        a = GetSensorA();
        newResult.Set();
    }
}

private void ThreadB()
{
    int b;

    while (true)
    {
        newResult.WaitOne();
        b = GetSensorB();         // or before "waitone"
        Console.WriteLine(a + b); // do something
    }
}
相关问题