mongoengine

Switch collection in mongoengine for find query

て烟熏妆下的殇ゞ 提交于 2020-01-05 02:21:49
问题 I've read mongoengine documentation about switching collection to save document. And test this code and it worked successfully: from mongoengine.context_managers import switch_db class Group(Document): name = StringField() Group(name="test").save() # Saves in the default db with switch_collection(Group, 'group2000') as Group: Group(name="hello Group 2000 collection!").save() # Saves in group2000 collection But the problem is when I want to find saved document in switch collection switch

mongoengine connect() in settings.py testing problem

本秂侑毒 提交于 2019-12-31 22:30:12
问题 I want to be able to do conditional connect() based on either I started django in testing mode or not. in my settings.py I use mongoengine connect() method to connect to my database but the problem is that I don't want to do that if I ran manage.py test Is there any way I can check if settings.py is being imported from tests or not, some flag maybe. something like if not IN_TESTS: connect() 回答1: I'm solving this with a custom test runner. Here is an example I based my solution off of: https:/

Update a MongoEngine document using a python dict?

强颜欢笑 提交于 2019-12-31 21:37:31
问题 Is it possible to update a MongoEngine document using a python dict? For example: class Pets(EmbeddedDocument): name = StringField() class Person(Document): name = StringField() address = StringField() pets = ListField(EmbeddedDocumentField(Pets)) p = Person() p.update_with_dict({ "name": "Hank", "address": "Far away", "pets": [ { "name": "Scooter" } ] }) 回答1: Pretty late to the game here, but FWIW, MongoEngine has a build in solution for this. Regardless if you want to create or update you

Trouble using MongoDB as backend for Django project (Django 1.7)

╄→尐↘猪︶ㄣ 提交于 2019-12-31 03:53:24
问题 I set up my app using the following tutorial, http://django-mongodb-engine.readthedocs.org/en/latest/topics/setup.html When I set my backend as detailed in this link in my settings.py, I get the following error: NotImplementedError: subclasses of BaseDatabaseIntrospection may require a get_table_list() method I have installed all the necessary packages (django-nonrel, djangotoolbox, mongodb-engine), but I'm still getting these errors. What might I be doing wrong/am I missing? It could very

MongoDB + Python - very slow simple query

时间秒杀一切 提交于 2019-12-25 16:53:14
问题 I have an open source energy monitor (http://openenergymonitor.org) which logs the power usage of my house every five seconds, so I thought this would be a perfect application to play with MongoDB. I have a Flask Python application running in Apache using MongoEngine to interface with MongoDB. Now I am running all of this on a RaspberryPi, so I'm not expecting incredible performance, but a simple query is taking around 20 seconds, which seems slow even for this limited hardware. I have the

Django DB Connection with mangoDB using mangoengine gives me error?

假装没事ソ 提交于 2019-12-25 07:40:05
问题 I am getting the connection error while connecting mangodb through django using mongoengine I have included following things to settings. mongoengine.connect('zaya', username='admin', password='secret') # Mongo DB Sessions SESSION_ENGINE = 'mongoengine.django.sessions' SESSION_SERIALIZER = 'mongoengine.django.sessions.BSONSerializer' Also I have created db with name zaya , user admin and password secrete To create this I have followed below link: http://petrkout.com/programming/setting-up

Mongoengine deferencing happens after using select_related()

六眼飞鱼酱① 提交于 2019-12-25 05:09:28
问题 This could be a stupid question if my understanding about select_related() is completely wrong. Here is the database design that I have. class UserAccount(Document): first_name = StringField(max_length = 20) last_name = StringField(max_length = 20) user_name = StringField(max_length = 20) friends = ListField(ReferenceField('self')) And the queryset is: u = UserAccount.objects.get(user_name="something").select_related() I've passed the result in 'u' to the Django templates. So I tried this in

custom _id fields Django MongoDB MongoEngine

喜欢而已 提交于 2019-12-25 02:09:07
问题 is it possible to use custom _id fields with Django and MongoEngine? The problem is, if I try to save a string to the _id field it throws an Invalid ObjectId eror. What I want to do is using my own Id's. This never was a problem without using Django because I caught the DuplicateKeyError on creation if a given id was already existing (which was even necessary to tell the program, that this ID is already taken) Now it seems as if Django/MongoEngine won't even let me create a custom _id field :

TSocket read 0 bytes Apache Thrift MongoDB

夙愿已清 提交于 2019-12-24 19:39:56
问题 I am developing a small application with RPC framework Apache Thrift and Python. I want to use MongoDB. I am using mongoengine connector and I defined thrift data model and generated code from it When storing tags in a list in the server all is fine. However, I get errors when trying to store tags in database Here Is my code server.py import os import sys from mongoengine import * sys.path.append(os.path.join( os.path.dirname(os.path.abspath(__file__)), 'gen-py')) from thrift.transport import

What is “reload()” for in MongoEngine

情到浓时终转凉″ 提交于 2019-12-24 11:29:33
问题 I have a statement like: jsonify_ok(data=mytag.reload().as_dict()) What role does reload() play? what's the normal situation for us to use reload()? 回答1: Document.reload() will check the database and update your data (I think in this case mytag but I can't see what this is) with any attributes that have been modified. This could be useful if the data could or has changed before calling jsonify_ok . Breaking down your data=mytag.reload() this says: "For document mytag , go to the database and