pymongo-2.x

Mongo query in python if I use variable as value

守給你的承諾、 提交于 2019-12-24 17:05:06
问题 Am trying to find documents from the mongo collection using the following query. db.collection_name.find({"id" : Id}) where Id is the variable am getting as input. But it doesn't work. If I hard code the value like this db.collection_name.find({"id" : "1a2b"}) it works. "id" is of string type and am using pymongo to access mongo DB. code : client = MongoClient("localhost:27017") db = client['sample_database'] Id = raw_input("enter id") cursor = db.collection_name.find({"id" : Id}) 回答1: Try

Abstract classes and PyMongo; can't instantiate abstract class

☆樱花仙子☆ 提交于 2019-12-18 09:44:55
问题 I created the empty abstract class AbstractStorage and inherited the Storage class from it: import abc import pymongo as mongo host = mongo.MongoClient() print(host.alive()) # True class AbstractStorage(metaclass=abc.ABCMeta): pass class Storage(AbstractStorage): dbh = host def __init__(self): print('__init__') Storage() I expected the output to be True __init__ however, the one I'm getting is True Traceback (most recent call last): File "/home/vaultah/run.py", line 16, in <module> Storage()

Abstract classes and PyMongo; can't instantiate abstract class

醉酒当歌 提交于 2019-12-01 08:07:21
问题 I created the empty abstract class AbstractStorage and inherited the Storage class from it: import abc import pymongo as mongo host = mongo.MongoClient() print(host.alive()) # True class AbstractStorage(metaclass=abc.ABCMeta): pass class Storage(AbstractStorage): dbh = host def __init__(self): print('__init__') Storage() I expected the output to be True __init__ however, the one I'm getting is True Traceback (most recent call last): File "/home/vaultah/run.py", line 16, in <module> Storage()