The addition of new records is even simpler. What does it have to do with our queries?Īn object represents all the data for a record in the User table. That is because the User is the Model, because the Model itself only represents the data structure. Let’s analyze how the statement was queried.įirst the User.objects, the User here, we already know that it is our Model, and since User has already been Model, why is it still object-like? This statement queried the user whose name in the database was alice. It is very simple to query the update and delete of the MongoEngine, such as queries, we can use: 1 The next thing is to explain how the data in the database can be edited and edited through the Model. Related course: Python Flask: Create Web Apps with Flask Access data Queries In this way, our data model is created, and the entire complete code is: 1įrom flask_mongoengine import MongoEngine We create a model with only two fields, name and email: 1 To use MongoEngine in Flask, first we need to configure MongoDB’s information in Flask before we initialize the MongoEngine with our server, so that we connect the database and the server, which can be said in code: 1Īfter you configure the mongodb information, you can create a data model using MongoEngine. You can use MongoEngine independently without relying on the Flask, but you can use it in combination with Flask. Here we are introducing the Flask extension of the MongoDB: MongoEngine. The main function of the data model is to show which fields our data contains, what type each field is, what is the attribute (unique, or one of several fixed values), and so on.This can help us to know the information of our data at all times when operating data, even if we don’t look at the data in the database. Now that we want to use the database to save data, we can use the native pymongo to operate MongoDB, but here we need to simplify our operations, so we need to create data models. ![]() Related course: Python Flask: Create Web Apps with Flask Creating data models Models ![]() MongoDB is a popular database, but unlike other databases it’s classified as a NoSQL database program (MongoDB uses JSON-like documents with schema). A better way is to use a database ( MongoDB) ![]() This can be cumbersome, every request needs to be read, file-writing, etc. In a simple REST service in the last article, our data is stored in the file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |