i have database named suvaider. contains 2 collection relation , reviews. have filled these 2 importing json files. have created models these 2 collections. while trying use these models data mongoengine returns empty array. i'm beginner i'm using mongodb first time flask. in advance!!!
# models.py flask import url_for suvaiderbackend import db class hotels(db.embeddeddocument): property_id = db.stringfield(max_length=255,required=true) name = db.stringfield(max_length=255,required=true) class relation(db.document): parent = db.embeddeddocumentfield('hotels') units = db.listfield(db.embeddeddocumentfield('hotels')) class reviews(db.document): property_id = db.stringfield(max_length=255,required=true) rating = db.intfield(default=0) review = db.stringfield() sentiment = db.stringfield(max_length=255) review_link = db.stringfield() #this __init__.py flask import flask flask.ext.mongoengine import mongoengine app = flask(__name__) app.config["mongodb_settings"] = {'db': "suvaider"} app.config["secret_key"] = "keep3h9secret" db = mongoengine(app) if __name__ == '__main__': app.run(debug=true)
according documentation mongoengine default converts document class name lowercase , use name of collection. in example looks collections named: relation , reviews. since have existing database different collections(notice spelling - first letter uppercase) should set custom collection name adding
meta = {'collection': 'collectionname'}
to documents.
class relation(db.document): parent = db.embeddeddocumentfield('hotels') units = db.listfield(db.embeddeddocumentfield('hotels')) meta = {'collection': 'relation'} class reviews(db.document): property_id = db.stringfield(max_length=255,required=true) rating = db.intfield(default=0) review = db.stringfield() sentiment = db.stringfield(max_length=255) review_link = db.stringfield() meta = {'collection': 'reviews'}
Comments
Post a Comment