Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Storing MongoDB Collection Name in Variable

$
0
0

I am attempting to store the name of a MongoDB collection in a variable and refer to that in a query. If I specify the name of the collection without quotes, my query runs, but if I place the name of my collection in a variable as a string, my query will not run.

Here is what I am trying to run. As mentioned, when "x" is replaced with P38, the query produces results, but does not produces results in its current form.

x = 'P38'cursor = db.x.find({})for item in cursor:    print(item)

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>