mongoengine

How to bulk transfer JSON via MongoEngine

How to bulk transfer JSON via MongoEngine Question: Trying to send a lot of data to MongoDB through MongoEngine. I start with a DataFrame that I write to JSON like this: result = df.to_json(orient="index") parsed = json.loads(result) json_data = json.dumps(parsed, indent=4) I then make it a little prettier using this: json_object = json.loads(json_data) json_formatted_str = …

Total answers: 2

Cannot deserialize properly a response using pymongo

Cannot deserialize properly a response using pymongo Question: I was using an API that were written in NodeJS, but for some reasons I had to re-write the code in python. The thing is that the database is in MongoDB, and that the response to all the queries (with large results) includes a de-serialized version with$id …

Total answers: 1

MongoEngine cannot connect through Atlas Uri string. Tried everything

MongoEngine cannot connect through Atlas Uri string. Tried everything Question: I’m new to programming and am building my first app.. I’m building a kivy app trying to use mongoDB as the database. I can connect to a localhost to query and create documents. I cannot get it to connect to the atlas no matter what …

Total answers: 1

mongoengine query for duplicates in embedded documentlist

mongoengine query for duplicates in embedded documentlist Question: I’m making a python app with mongoengine where i have a mongodb database of n users and each user holds n daily records. I have a list of n new record per user that I want to add to my db I want to check if a …

Total answers: 2

How to convert Python mongongine object (Document) to dictionary?

How to convert Python mongongine object (Document) to dictionary? Question: I have a collection of object stored in mongo which I retrieve with python mongoengine. I wish to return a lit of these object in json format to an http request but it seems IMPOSSIBLE to do. This is the piece of code where I …

Total answers: 2

Subclassing document in separate collections in Mongoengine

Subclassing document in separate collections in Mongoengine Question: I have a collection in Mongoengine with long list of fields which contains some documents: class Component(Document): name = StringField(unique=True) title = StringField(required=True) description = StringField(default=”) # And so on… Now I want another collection similar to the first collection with some extra stuffs. So I used …

Total answers: 3

Calling certain functions when initializing a new mongoengine document

Calling certain functions when initializing a new mongoengine document Question: I’m trying to define a Document class that has some fields that have their values automatically calculated when a new document is created. So far I have succeeded in doing that by extending the __init__ function like this: class URLDoc(Document): url = fields.URLField(requierd=True) domain = …

Total answers: 3

How to query PointField – MongoEngine

How to query PointField – MongoEngine Question: I was trying to update PointField in my flask app with upsert_one. But it always inserts new document. I know the problem is with the query which I’m passing. Below is my model. class Location(db.Document): location_name = db.StringField(required=True) geoCoords = db.PointField() And the update query. Location.objects(geoCoords=loc[“geoCoords”]).upsert_one(location_name=loc[“location_name”], geoCoords=loc[“geoCoords”]) #loc[“geoCoords”] …

Total answers: 2

What is universal method for `get or default` in python?

What is universal method for `get or default` in python? Question: I would like to get an attribute of mongoengine model object but it’s missing (how it’s often in mongo): unit.city gives me AttributeError unit.get(‘city’) says that ‘Unit’ object has no attribute ‘get’ and I can’t find any appropriate method by dir(unit). So I have …

Total answers: 2

NotUniqueError: Tried to save duplicate unique keys

NotUniqueError: Tried to save duplicate unique keys Question: I keep getting the above mentioned error. I have deleted the existing db field id which was set to unique. But on save I got the below exception raise NotUniqueError(message % unicode(err)) NotUniqueError: Tried to save duplicate unique keys (E11000 duplicate key error index: test.users.$id_1 dup key: …

Total answers: 2