txmongo icon indicating copy to clipboard operation
txmongo copied to clipboard

txmongo list of collections not returned

Open ashishRay12 opened this issue 7 years ago • 8 comments

txmongo dosen't return list of all collections.Inserts and deletes works just fine.Below is the code that is being used.


from txmongo.connection import ConnectionPool
from twisted.internet import defer, reactor
import time


@defer.inlineCallbacks
def mongoHost():
    mongodb_uri = "mongodb://%s:%s" % ('127.0.0.1', '27017')
    mongo = yield ConnectionPool(mongodb_uri)
    defer.returnValue(mongo)


@defer.inlineCallbacks
def query_to_db():
    mongo = yield mongoHost()
    db = mongo['clients']
    coll = yield db.collection_names() # <------------------dosen't works!
    # coll = yield db.facebook.find({})  <------------------works !
    print coll

if __name__ == '__main__':
    reactor.callLater(1, query_to_db)
    reactor.run()

ashishRay12 avatar Jun 21 '17 20:06 ashishRay12

Oops, you are right, it seems to be broken on MongoDB 3.x

IlyaSkriblovsky avatar Jun 21 '17 20:06 IlyaSkriblovsky

As a workaround you can probably try yield db.command("listCollections")

IlyaSkriblovsky avatar Jun 21 '17 20:06 IlyaSkriblovsky

@IlyaSkriblovsky thanks :)

ashishRay12 avatar Jun 21 '17 20:06 ashishRay12

Nice find, time for another component test. :)

psi29a avatar Jun 21 '17 20:06 psi29a

@IlyaSkriblovsky @psi29a it works in MongoDB 3.0.12. verified

anekix avatar Jun 21 '17 20:06 anekix

@ashishRay12 what version are you using?

anekix avatar Jun 21 '17 20:06 anekix

@anekix i am using MongoDB 3.2.14.

ashishRay12 avatar Jun 21 '17 20:06 ashishRay12

collection_names() is using system.namespaces special collection that was deprecated in 3.0 and probably removed in 3.2: https://docs.mongodb.com/manual/reference/system-collections/#.system.namespaces

IlyaSkriblovsky avatar Jun 21 '17 20:06 IlyaSkriblovsky