How to use $http to add, delete, modify and query MongoLab data tables in AngularJS_AngularJS
Main page: Load Course Add New Course Above, the content display of course_list.html, add_course.html and edit_course.html displayed on the page is related to the toggleAddCourseView and toggleEditCourseView values, and the toggleAddCourseView and toggleEditCourseView values will be controlled by methods. Create databases and tables on Mongolab → https://mongolab.com → Register → Login → Create new → Select Single-node Check the Sandbox and enter the Database name as myacademy. → Click on the newly created Database → Click Add collection The name is course → Click on the course collection. → Click add document multiple times to add multiple pieces of data Controller $scope.courses = []; var url = “https://api.mongolab.com/api/1/databases/my-academy/collections/course?apiKey=myAPIKey”; var cOnfig= {params: {apiKey: “…”}}; $scope.toggleAddCourseNew = false; $scope.toggleEditCourseView = false; //list $scope.loadCourses = function(){ $http.get(url, config) .success(function(data){ $scope.courses = data; }); } //Add to $scope.addCourse = function(course){ $http.post(url, course, config) .success(function(data){ $scope.loadCourses(); }) } //Show changes $scope.editCourse = function(course){ $scope.toggleEditCourseView = true; $scope.courseToEdit = angular.copy(course); } //Revise $scope.updateCourse = function(courseToEdit){ var id = courseToEdit._id.$oid; $http.put(url + “/” + id, courseToEdit, config) .success(fucntion(data){ $scope.loadCourses(); }) } //delete $scope.delteCourse = function(course){ var id = course._id.$oid; $http.delete(url+ “/” + id, config) .success(function(data){ $scope.loadCourses(); }) } $scope.toggleAddCourse = function(flag){ $scope.toggleAddCourseView = flag; } $scope.toggleEditCourse =…
MongoDB add, delete, modify
Introduction to MongoDB driver types 1. MongoDB official driver: mongo-csharp-driver, download address: https://github.com/mongodb/mongo-csharp-driver/downloads 2. Third-party driver samus , this is a frequently used driver with a relatively fast update frequency. In addition to supporting general operations, the samus driver also supports Linq Introduction to MongoDB driver types 1. MongoDB official driver: mongo-csharp-driver, download address: https://github.com/mongodb/mongo-csharp-driver/downloads 2. The third-party driver samus is a commonly used driver with a relatively fast update frequency. In addition to supporting general operations, the samus driver also supports Linq and Lambda expressions. Download address: https://github.com/samus/mongodb-csharp. The operation process of the two mongodb drivers on the mongodb database is basically the same, but there are differences in the implementation methods. For example, the samus driver not only supports general formal operations, but also supports Linq and Lambda expressions. Use MongoDB official driver to operate the database Unzip the package and get the following two files: MongoDB.Bson.dll: Serialization, Json related MongoDB.Driver.dll: mongodb driver Add references and introduce the above two DLLs into the project Introducing namespaces into code using MongoDB.Bson; using MongoDB.Driver; Obtain database connection service string cOnnectionString= ” mongodb://localhost ” ; //mongodb://[username:password@]hostname[:port][/[database][?options]] MongoServer server = MongoServer.Create(connectionString); // Connect to a MongoServer Get a reference to the specified…
Mongodb write, delete, update
1. Mongodb creates databases and collections The creation of mongodb databases and collections is implicit. This means that there is no need to write a separate create database statement. Just use the use keyword directly. Run under bin/mongo shell: use test; This will generate a test database. If you leave without writing, the system will automatically delete it. Sets are also implicit and do not need to be specifically referred to 1. Mongodb creates databases and collections Creation of mongodb databases and collections is implicit. This means that there is no need to write a separate create database statement. Just use the use keyword directly. Run under bin/mongo shell: use test; This will generate a test database. If it is not written and left, the system will automatically delete it. Collections are also implicit. You don’t need to specify them. If you directly insert a document, a collection will be generated. 2. Document writing Insert using insert: db.user.insert({“name” : “gang”}); user is the collection name, and a piece of data is written. 3. Document deletion Document deletion uses the remove keyword. db.user.remove(); Delete all data under user. If you specify to delete data under specific conditions, you need to add…
Introduction to MongoDB Learning (3): MongoDB Add, Delete, Check and Modify
For novices like us, the most important thing is not the management of the database, nor the performance of the database, nor the expansion of the database, but how to make good use of this database, that is, a database provides The most core function is addition, deletion, checking and modification. Because MongoDB stores data in document mode, when operating its data, it is also based on documents. For novices like us, the most important thing is not the management of the database, nor the performance of the database, nor the expansion of the database, but how to make good use of this database, which is the core function provided by a database. , add, delete, check and modify. Because MongoDB stores data in document mode, when operating its data, it is also based on documents. Then our implementation of adding, deleting, checking and modifying is also based on documents. Students who don’t know what documents are can take a look at the basic concepts introduced in the previous article. 1. Insert document The basic method of inserting documents into a MongoDB collection is insert: single insert > document = {key : value} > db.collectionName.insert(document) Batch insert > documents =…
MongoDB (3) Add, delete, modify and query
MongoDB is a non-relational database, and there is a big difference between the addition, deletion, modification and query of traditional databases. Here is just an outline of the knowledge points. When it is actually used, we can Baidu for detailed usage. Can. Let’s look at the major aspects first: 1. I won’t go into too much detail about the insertion and deletion inside. Relatively speaking, there are relatively few knowledge points. Let’s take a look at the updates first, As a non-relational database, MongoDB is very different from the addition, deletion, modification and search of traditional databases. Here is just an outline of the knowledge points. When it is actually used, we can search the detailed usage on Baidu. Let’s look at the major aspects first: First, I won’t go into too much detail about the insertion and deletion. There are relatively few knowledge points. Let’s take a look at the updates first. Common operations are still very useful and we need to use them flexibly according to the actual situation. Here are just some knowledge points. Baidu needs examples to learn how to use them: 2. The same is true for queries. Take a look at the summary of…
Getting Started with MongoDB – Add, Delete, Modify and Query
mongodb started successfully, and then it is time to perform a series of operations. Let’s open another cmd and enter the [mongo] command to open the shell, which is the client of mongodb. The default connection is the test database. I set the collection (table) here to student. Figure 1: 1. Add insert syntax: db.set.insert({Col1: column value 1, Col2: column value 2,, Coln: column value n} Mongodb started successfully, and then it is time to perform a series of operations. Let’s open another cmd and enter the [mongo] command to open the shell, which is the client of mongodb. The default connection is the “test” database. I set the collection (table) here to student. Figure 1: 1. Add insert Syntax: db.set.insert({“Col1″:”Column value 1″,”Col2″:”Column value 2″,…,”Coln”:”Column value n”}) 2. Find find 2.1 All queries Syntax: db.collection.find() 2.2 Conditional query Syntax: db.set.find({“Col1″:”Column value 1″,”Col2″:”Column value 2″,…,”Coln”:”Column value n”}) Operation example: Add+Find Note: The “_id” field is the GUID added to us by the database by default to ensure the uniqueness of the data. 3.Modify 3.1 All modifications update Syntax: db.set.update({“Col”:”Column value”},{“Col2″:”Column value 2″,…,”Coln”:”Column value n”}) Note: The first parameter {…} is the “search condition”, and the second parameter {…} is the “value…
Node.js uses mongoose to operate the database to implement the add, delete, modify and check functions of the shopping cart.
The example in this article describes how node.js uses mongoose to operate the database to implement the add, delete, modify, and check functions of the shopping cart. Share it with everyone for your reference, the details are as follows: 1. Database operation statements Mongoose implements the operation of each collection through model. You need to define model:goods before using it. ①. Add data: Query a record from the collection and return the doc. After operating the doc, save it to the collection through save() goods.findOne({productId},(err,goodsDoc)=>{ goodsDoc.productNum=1; goodsDoc.save(err,doc); }); ②. Delete data: model.remove(conditions,callback(){}) ③. Modify data: model.update(conditions,updates,callback(){}) ④. Query data: model.find(conditions,callback(){}) 2. Add to shopping cart Create a new user collection in mongodb. There is a cartList array in user. When the user clicks to add a shopping cart, a post request is sent to the front end including the user and product IDs. Then the corresponding user is queried on the backend, and the product ID in the cartList is compared. If it is among them, the product quantity is +1. Otherwise, the product information is queried from the product collection and inserted into the cartList array. Front-end add shopping cart request: addCart(productId){//Add to shopping cart axios.post(‘./users/addCart’,{ userId:”100000077″, productId: productId…
How to add, delete, and modify data using the ModelForm provided by Django
In the previous article, we wrote about how Django adds, deletes, and modifies data based on classes. Although the method is simple, novices may not be very clear about its principles. So this time we will use the ModelForm method provided by Django to add, delete, and modify data. This is a method of adding, deleting, and modifying existing models. A simple example to illustrate, the premise is that you already have the basic knowledge of Django to create project applications: 01. First create a simple model. The model has only three text fields, title, content, and date_added, as follows: # models.py from django.db import models from django.utils import timezone class Article(models.Model): title = models.CharField(‘title’, max_length=100) text = models.TextField(‘content’) date_added = models.DateTimeField(default=timezone.now) def __str__(self): return self.title After creating the model, don’t forget to generate the database, makemigrations method (generate migration files), migrate (migrate to the database). 02. Create a form.py file in the project. My project name here is app1, and create a form class ArticleForm that inherits a ModelForm. Its subclasses contain many built-in methods, and I can do them all. For its coverage, interested students can read the official documentation, which is very detailed. Document address: https://docs.djangoproject.com/zh-hans/2.1/topics/forms/modelforms/#django.forms.ModelForm, #…