Using the getColletion function in Pymongo

Asked

Viewed 14 times

0

some can help me with the following problem?

Inside mongoDB, the colletion was created with space, example: "Mkt pipe". mongoDB allowed to do this kind of thing.

I created the following route to perform the query directly in the database:

@metricas.route('/counter_source', methods=['POST'])

    def counter_source():
        payload = json.loads(request.data, object_hook=datetime_parser)
        query = payload.get("query")
        count = app.db.getCollection("mkt pipe").find(query).count()
    
        return str(count)

on account of getCollection pymongo returns me the following error:

TypeError: 'Collection' object is not callable. If you meant to call the 'getCollection' method on a 'Database' object it is failing because no such method exists.

If it wasn’t for the blessed space, all you had to do was make it work:

count = app.db.mktpipe.find(query).count()

Has anyone ever had this problem that can help me?

Hug

  • Are you sure the method getCollection is there? Have you tried app.db["mkt pipe"].find(query).count()?

  • @Paulomarques works like this yes. Only method I hadn’t remembered to test. Thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.