mongoengine

GraphQL搭配MongoDB入门项目实战

浪尽此生 提交于 2021-02-12 18:15:32
什么是GraphQL GraphQL 是一种面向 API 的查询语言。在互联网早期,需求都以 Web 为主,那时候数据和业务需求都不复杂,所以用 RestAPI 的方式完全可以满足需求。但是随着互联网的发展,数据量增大,业务需求多变。还有各种客户端需要接口适配,基于 RestAPI 的方式,显得越来呆板,因此 GraphQL 便应运而生。它至少可以提供以下三个方面的优势 GraphQL 提供更方便的 API 查询 不同的客户端有时候需要返回的数据格式不同,之前使用 RestAPI 的方式,需要后端针对每一个客户端提供单独的接口。随着业务需求的增加,维护的成本随机呈指数级跃升。而使用 GraphQL 就比较开心了,只需要写一套接口即可 解决前后端过于依赖 在开发的过程中,前端需要和后端反反复复确认各个字段,防止到时候开发到一半,因为没有对好字段,要大块大块地改代码。现在有 GraphQL 就比较方便了,你需要什么类型的字段,就自己写对应的查询语法 节约网络和计算机内存资源 之前通过 RestAPI 的方式写接口,有一个很大的问题在于,对于接口的定义,需要前期做大量的工作,针对接口做各种力度的拆分,但即使这样,也没办法应对需求的风云突变。有时候需要返回的仅仅是某个用户的某一类型的数据,但不得不把该用户的其他信息也一并返回来,这既浪费了网络的资源,也消耗了计算机的性能。显然不够优雅

Insert data by pymongo using mongoengine ORM in pyramid

邮差的信 提交于 2021-02-10 15:54:50
问题 I want to use pymongo connection and methods to work with mongodb, but at the same time i want using mongoengine ORM. Sample: class User(Document): email = StringField(required=True) first_name = StringField(max_length=50) last_name = StringField(max_length=50) john = User(email='jonhd@example.com') john.first_name = 'Jonh' john.last_name = 'Hope' And now i want to insert new formed document User into my 'test_collection'. In case using only mongoengine i can do this: connect('test_database')

Migrations in mongoengine: InvalidId

只谈情不闲聊 提交于 2021-02-06 09:12:57
问题 I am working with mongoengine and trying to do a simple migration. I have a field which I would like to migrate from being a StringField to a ReferenceField to another Object. I planned on doing the migration by hand, first constructing the new object based on the string that comes from the old StringField and then setting it explicitly. The problem is I cannot even access one of the top level documents anymore once I changed the field type. Is it required to create a "dummy" field in the my

How do I retrieve and print pymongo.cursor.Cursor objects?

霸气de小男生 提交于 2021-01-29 18:42:53
问题 I am creating a simple database CRUD manager using python and connecting it to a MongoDB database. I have connected to my cluster and have retrieved posts before using the exact same method. However this time when I tried, it does not work. The error is when I try to print the dictionary object from a collection. The collection only contains a single object with {title:"book"} In the following code, I have retrieved a pymongo.cursor object as the variable name "thedb". print(thedb) will

mongodb mongoengine filter document on nexted EmbeddedDocumentLIst fields

本秂侑毒 提交于 2021-01-29 15:23:10
问题 I have a document with a EmbeddedDocumentList inside an other EmbeddedDocumentlist, I need to filter the collections retrieving only the documents that have a specified value for a field inside the inner EmbeddedDocumentList the reduced version of my models is: class RecipeIngredient(EmbeddedDocument): ingredient = ReferenceField(Ingredient, required=True) quantity = IntField(required=True) class RecipeLocalData(EmbeddedDocument): price = FloatField(required=True) enabled = BooleanField

Cause of mongoengine.errors.InvalidQueryError

人盡茶涼 提交于 2021-01-28 10:18:24
问题 The journey with Flask, MongoDB and MongoEngine continues. I've (hopefully) synced up the database with my model in a normal fashion, yet when I attempt to query the database for something as simple as an address name, I get this message: mongoengine.errors.InvalidQueryError InvalidQueryError: Not a query object: {'wsgi.multiprocess': False, 'SERVER_SOFTWARE': 'Werkzeug/0.9.6', 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/result', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING':

Cause of mongoengine.errors.InvalidQueryError

前提是你 提交于 2021-01-28 10:12:25
问题 The journey with Flask, MongoDB and MongoEngine continues. I've (hopefully) synced up the database with my model in a normal fashion, yet when I attempt to query the database for something as simple as an address name, I get this message: mongoengine.errors.InvalidQueryError InvalidQueryError: Not a query object: {'wsgi.multiprocess': False, 'SERVER_SOFTWARE': 'Werkzeug/0.9.6', 'SCRIPT_NAME': '', 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/result', 'SERVER_PROTOCOL': 'HTTP/1.1', 'QUERY_STRING':

MongoDB : How to design schema based on application access patterns?

徘徊边缘 提交于 2020-12-04 12:00:09
问题 As someone that comes from DynamoDB, modeling a MongoDB schema to really fit deeply into my application is kinda confusing, specially since it has the concept of references and from what I read is not recommended to keep duplicated data to accomodate your queries. Take the following example (modeled in mongoengine, but shouldn't matter) : #User class User(Document): email = EmailFieldprimary_key=True) pswd_hash = StringField() #This also makes it easier to find the Projects the user has a

MongoDB : How to design schema based on application access patterns?

对着背影说爱祢 提交于 2020-12-04 11:59:45
问题 As someone that comes from DynamoDB, modeling a MongoDB schema to really fit deeply into my application is kinda confusing, specially since it has the concept of references and from what I read is not recommended to keep duplicated data to accomodate your queries. Take the following example (modeled in mongoengine, but shouldn't matter) : #User class User(Document): email = EmailFieldprimary_key=True) pswd_hash = StringField() #This also makes it easier to find the Projects the user has a

MongoDB : How to design schema based on application access patterns?

戏子无情 提交于 2020-12-04 11:59:27
问题 As someone that comes from DynamoDB, modeling a MongoDB schema to really fit deeply into my application is kinda confusing, specially since it has the concept of references and from what I read is not recommended to keep duplicated data to accomodate your queries. Take the following example (modeled in mongoengine, but shouldn't matter) : #User class User(Document): email = EmailFieldprimary_key=True) pswd_hash = StringField() #This also makes it easier to find the Projects the user has a