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

I tried the following code and it throws an error saying Collection' object is not callable. If you meant to call the 'IntField' method on a 'Collection' object it is failing because no such method exists.

app = Flask(__name__)
app.secret_key = b'\xcc^\x91\xea\x17-\xd0W\x03\xa7\xf8J0\xac8\xc5'

# Database
client = pymongo.MongoClient('localhost', 27017)
db = client.User_login


class User(db.Document):
    user_id     =   db.IntField( unique=True )
    first_name  =   db.StringField( max_length=50 )
    last_name   =   db.StringField( max_length=50 )
    email       =   db.StringField( max_length=30 )
    password    =   db.StringField( )
    ip          =   db.StringField( )



 def set_password(self, password):
        self.password = generate_password_hash(password)

    def get_password(self, password):
        return check_password_hash(self.password, password)

class UserParameters(db.Document):
    user_id     =   db.IntField( unique = True )
    session_id  =   db.IntField( required = True )


class Articles(db.Document):
    articleID   =   db.StringField( )
    Datetime   =   db.DateTimeField( )
    Category    =   db.StringField( )
    Subcategory =   db.StringField( )
    Headline     =   db.StringField( )
    Summary     =   db.StringField( )
    Entire_News =   db.StringField( )
    News_Link   =   db.StringField( )
    Author   =   db.StringField( )

class Rating(db.Document):
    user_id     =   db.IntField( )
    articleID   =   db.StringField( max_length=10 )
    Rating      =   db.IntField( )

class Clickstream(db.Document):
    user_id     =   db.IntField( )
    session_id   =   db.StringField( max_length=10 )
    articleID       =   db.StringField( )
    article_rank      =   db.IntField( )
    article_clicked     =   db.IntField( )
    time_spent          =   db.StringField( )

I am not sure if db is supposed to be a database or collection, I tried both and still got the error. I am using latest version of Mongodb In the above code User_login is the name of database.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source