[Python-porting] Ask a question about Python accessing mongodb. Thanks.

zhongxiaobin76 zhongxiaobin76 at aliyun.com
Mon Oct 30 01:48:27 EDT 2017
When I found problems in the process of accessing mongodb with Python, Who can I ask for help?
I want to create an object with Python to receive a document in mongodb, and the document format is like this:{ "_id" : ObjectId("59f2d36fb934f31fdc002485"), "Name" : "???1711", "Date" : "20
14/12/12", "data" : [ { "time" : "0901", "Open" : "13280.00", "Max" : "13280.00"
, "Min" : "13280.00", "Close" : "13280.00", "Volume" : "0", "Amount" : "580", "S
ettlement" : "0.00", "EXPMA1" : "13304.91", "EXPMA2" : "13301.51" }, { "time" :
"0902", "Open" : "13280.00", "Max" : "13280.00", "Min" : "13280.00", "Close" : "
13280.00", "Volume" : "0", "Amount" : "580", "Settlement" : "0.00", "EXPMA1" : "
13301.08", "EXPMA2" : "13300.66" }]}There are about 300 records in the data.
How do I write an object that encapsulates the Mongo document like the object VtBarData in the code below?def loadBar(self, dbName, collectionName, days):
    print "zxb ctaEngine CtaEngine loadBar days = ", days
    startDate = self.today - timedelta(days)
    
    d = {'datetime':{'$gte':startDate}}
    barData = self.mainEngine.dbQuery(dbName, collectionName, d, 'datetime')
    
    l = []
    for d in barData:
        print "zxb ctaEngine CtaEngine loadBar d = ", d
        bar = VtBarData()
        bar.__dict__ = d
        l.append(bar)
    return l
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-porting/attachments/20171030/3cd5ba4e/attachment.html>


More information about the Python-porting mailing list