mongoengine

PyMongo/Mongoengine equivalent of mongodump

喜欢而已 提交于 2020-01-23 05:51:24
问题 Is there an equivalent function in PyMongo or mongoengine to MongoDB's mongodump ? I can't seem to find anything in the docs. Use case: I need to periodically backup a remote mongo database. The local machine is a production server that does not have mongo installed, and I do not have admin rights, so I can't use subprocess to call mongodump . I could install the mongo client locally on a virtualenv, but I'd prefer an API call. Thanks a lot :-). 回答1: For my relatively small small database, I

PyMongo vs MongoEngine for Django

让人想犯罪 __ 提交于 2020-01-22 05:15:09
问题 For one of my projects I prefered using Django+Mongo . Why should I use MongoEngine , but not just PyMongo ? What are advantages? Querying with PyMongo gives results that are allready objects , aren't they? So what is the purpose of MongoEngine? 回答1: I assume you have not read the MongoEngine claim. MongoEngine is a Document-Object Mapper (think ORM, but for document databases) for working with MongoDB from Python. This basically say it all. In addition: your claim that Pymongo would deliver

Get username in url [Django] [mongoengine]

混江龙づ霸主 提交于 2020-01-16 19:57:42
问题 I am using django 1.7 with mongoengine. I have created a class Projects : class Projects(Document): user = ReferenceField(User, reverse_delete_rule=CASCADE) p_name = StringField(max_length=70, required=True) author = StringField(max_length=70, required=True) url = StringField(max_length=200, required=True) short_discription = StringField(max_length=100, required=True) long_discription = StringField() logo_url = StringField(max_length=200, required=False) logo = ImageField(size=(250, 250, True

mongoengine +django how to count the number of items of same content

让人想犯罪 __ 提交于 2020-01-16 12:24:07
问题 I want to count all the numbers of different values in a field.there is no "annotate()" to use in mongoengine ,then how could i count the number and order them by numbers The only way i thought out to solve this is use"distinct()"to find out the different values and then use "count()"to count each of the values it's a stupid way to realize the result i want Do you have any other ways ? 回答1: MongoEngine has some map reduce helpers that should meet your needs. The Queryset method item

Mongoengine reference another document's field

坚强是说给别人听的谎言 提交于 2020-01-15 12:31:22
问题 Is it possible to do something like this? class Doc1: fieldd1 = StringField() class Doc2: fieldd2 = ReferenceField(Doc1.fieldd1) Or should I just reference the Doc and then get the field information whenever I need it 回答1: This not posible and it is reference to document. To get fieldd1 you must do: class Doc1(Document): fieldd1 = StringField() class Doc2(Document): fieldd2 = ReferenceField(Doc1) Doc2.objects.first().fieldd2.fieldd1 If you want just include document to another as part of one

mongoengine save method is deprecated?

寵の児 提交于 2020-01-15 10:11:49
问题 I wonder why my python says that mongoengine save() method is deprecated? I don't see any info about this into official documentation https://mongoengine.readthedocs.io/en/v0.9.0/apireference.html class MyModel(Document): user_id = StringField(required=True) date = DateTimeField(required=True, default=datetime.datetime.now) my = MyModel() my.user_id = 'user' my.save() and now i see: /Library/Python/2.7/site-packages/mongoengine/document.py:340: DeprecationWarning: save is deprecated. Use

Specifying collection name with MongoEngine

落爺英雄遲暮 提交于 2020-01-13 08:43:27
问题 Once content is added the name of the collection is defaulted to the name of the class. Is it possible to specify the collection name or is my approach wrong? Using the code I have my collection is then named "mongo_engine_python" by default. from mongoengine import * try: connect( db='MongoEngine_Test', host="mongodb://localhost:27017/" ) print("Connection successful") except: print("Unable to connnect") class MongoEnginePython(Document): item_name = StringField(max_length=200, required=True

Querying a list in mongoengine; contains vs in

时光毁灭记忆、已成空白 提交于 2020-01-11 03:27:05
问题 I have a ListField in a model with ids (ReferenceField), and I need to do a query if a certain id is in that list. AFAIK I have 2 options for this: Model.objects.filter(refs__contains='59633cad9d4bc6543aab2f39') or: Model.objects.filter(refs__in=['59633cad9d4bc6543aab2f39']) Which one is the most efficient for this use case? The model looks like: class Model(mongoengine.Document): refs = mongoengine.ListField(mongoengine.ReferenceField(SomeOtherModel)) From what I can read in the mongoengine

Querying a list in mongoengine; contains vs in

人盡茶涼 提交于 2020-01-11 03:27:05
问题 I have a ListField in a model with ids (ReferenceField), and I need to do a query if a certain id is in that list. AFAIK I have 2 options for this: Model.objects.filter(refs__contains='59633cad9d4bc6543aab2f39') or: Model.objects.filter(refs__in=['59633cad9d4bc6543aab2f39']) Which one is the most efficient for this use case? The model looks like: class Model(mongoengine.Document): refs = mongoengine.ListField(mongoengine.ReferenceField(SomeOtherModel)) From what I can read in the mongoengine

How to repopulate WTForms

倾然丶 夕夏残阳落幕 提交于 2020-01-07 04:00:33
问题 so i have made a form in WTForms with an edit button which allows the user to edit the previous data in the form. The problem i have is fetching the new data from the form.when i do request.form i get the following: ImmutableMultiDict([('csrf_token', u'20130702225444##3f1c28cecaf55dc0e441d9820dfb52bb6df3d200'), ('csrf_token', u'20130702225444##3f1c28cecaf55dc0e441d9820dfb52bb6df3d200'), ('csrf_token', u'20130702225444##3f1c28cecaf55dc0e441d9820dfb52bb6df3d200'), ('csrf_token', u