TypeError: 'CommandCursor' object is not subscriptable 問題解決


TypeError: 'CommandCursor' object is not subscriptable

我用的是pymongo 查詢出來數據然后報這個錯誤

timer_object_id_list = TimerServer._get_collection().aggregate(
                    [{'$sort':{'timer_time':-1}},
                     {'$match':{'timer_status':'0'}},{"$group":{"_id":"$timer_object_id"}}])['result']

查詢了消息發現查詢出來的數據類型是commandcursor 不能帶有['result']
於是去掉

timer_object_id_list = TimerServer._get_collection().aggregate(
                    [{'$sort':{'timer_time':-1}},
                     {'$match':{'timer_status':'0'}},{"$group":{"_id":"$timer_object_id"}}])
  • 注意:后面的數組操作也要更換需要轉換成list具體可以看pymongo的CommandCursor源碼可以看看有哪些屬性也可查詢官網點擊此處

轉發請寫明出處!謝謝! 本文地址:https://www.cnblogs.com/ontoweb-zp/p/9166606.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM