MongoDB installation starts adding, deleting, and modifying documents

Add the decompressed bin path of mongodb to the environment variable to create a.bat and b.bat files: a.bat content: mongod –dbpath F:\MongoData b.bat content: mongo 127.0 .0.1:27017/admin a.bat is to start the mongodb server, –dbpath is used to specify the storage path of the data b.bat is to start the mongo shell (ie: js engine), admin Add the bin path of mongodb decompression to the environment variable Create a.bat and b.bat files: a.bat content: mongod –dbpath F:\MongoData b.bat content: mongo 127.0.0.1:27017/admin a.bat is to start the mongodb server, –dbpath is used to specify the storage path of the data b.bat is to start the mongo shell (ie: js engine), and admin is used to specify which database Start a.bat and see 2014-10-14T22:35:48.734+0800 [initandlisten] waiting for connections on port 270 17 The explanation is ok Don’t close the window, that is the mongo server Restart b.bat: MongoDB shell version: 2.6.5 connecting to: 127.0.0.1:27017/admin Seeing this description, the mongo shell has been started. The 6 in the middle of 2.6.5 is an even number, which represents a stable release version, and the odd number represents a development version A few simple commands: Create database: > use foobar switched to db foobar If…

C# simple operation example of adding, deleting, modifying and querying MongoDB

The current version of the C# driver used by MongoDB is 1.6.0 Download address: https://github.com/mongodb/mongo-csharp-driver/downloads 1, Connect to database The code is as follows:                                                                                                        private const string cOnn= “mongodb://127.0.0.1:27017”;                                                                                                                                                                 string dbName = “mongodb_name”;                                                                                                                                                                                                                           //Create a data connection              MongoServer server = MongoServer.Create(conn); col = db.GetCollection(tbName); 2. Insert data Because MongoDB does not have the concept of a table, you must define your own data model before inserting data User.cs The following is the code for adding data The code is as follows:                                                                                                                                      // Content /// Article ID /// Channel ID /// public static void Add(User t) { //Create data connection MongoServer server = MongoServer.Create (conn); //Get the specified database Insert col.Insert(t); } 3. Delete operation The code is as follows:                                                                                                                                                                  >         ///           public static void Delete(string objId)                                                                                                                                                                          ; /P> IMongoQuery query = Query.EQ(“_id”, new ObjectId(objId));           col.Remove(query);                                                                                                                                                                                                . Summary> /// Modify according to ObjectID ///   public static void Update(User t) { //Create data connection MongoServer server = MongoServer.Create(conn); //Get the specified database MongoDatabase db = server .GetDatabase(dbName); //Get the table             BsonDocument bd = BsonExtensionMethods.ToBsonDocument(t); IMongoQuery query = Query.EQ(“_id”, t.Id);     col.Update(query, new UpdateDocument(bd)); }5. Conditional query (simple) The code is as follows:                                                                                                                                                           > Public static TuCao SelectOne(string objId) {…

Example of adding, deleting, modifying and checking functions of nodejs operating mongodb

The example in this article describes the add, delete, modify and query functions of nodejs operating mongodb. Share it with everyone for your reference, the details are as follows: Install relevant modules If you use this, you need to install the modules it needs first and enter them in the root directory npm install mongodb –save Perform module installation. After successful installation, you can proceed with the following steps. Introduction of files The following is the relevant code I wrote, put it in the relevant directory that you can reference, I put it in the root directory of express function Mongo(options) { this.settings = { url: ‘mongodb://localhost:27017/jk’, MongoClient:require(‘mongodb’).MongoClient, assert:require(‘assert’) }; for(let i in options){ this.settings[i] = options[i]; } this._run = function (fun) { let that = this; let settings = this.settings; this.settings.MongoClient.connect(this.settings.url, function (err, db) { settings.assert.equal(null, err); console.log(“Connected correctly to server”); fun(db, function () { db.close(); }); }); }; this.insert = function (collectionName, data, func) { //Add data let insertDocuments = function (db, callback) { let collection = db.collection(collectionName); collection.insertMany([ data ], function (err, result) { if (!err) { func(true); } else { func(false); } callback(result); }); }; this._run(insertDocuments); }; this.update = function (collectionName, updateData, data, func) { //update…

Node.js example code for adding, deleting, modifying and querying MongoDB

Introduction to MongoDB MongoDB is an open source, document-based NoSQL database program. MongoDB stores data in JSON-like documents, making it more flexible and convenient to operate. Documents in a NoSQL database correspond to a row in a SQL database. Grouping a group of documents together is called a collection, which is roughly equivalent to a table in a relational database. In addition to being a NoSQL database, MongoDB also has some features of its own: •Easy to install and set up •Use BSON (a JSON-like format) to store data •Mapping document objects to application code is easy •Highly scalable and usable, and supported out-of-the-box without the need to define structures in advance •Supports MapReduce operations to compress large amounts of data into useful aggregate results •Free and open source •…… Connect to MongoDB In Node.js, the Mongoose library is usually used to operate MongoDB. Mongoose is a MongoDB object modeling tool designed to work in asynchronous environments. const mOngoose= require(‘mongoose’); mongoose.connect(‘mongodb://localhost/playground’) .then(() => console.log(‘Connected to MongoDB…’)) .catch( err => console.error(‘Could not connect to MongoDB… ‘, err)); Schema Everything in Mongoose starts with a pattern. Each schema maps to a MongoDB collection and defines the shape of the documents in that…

C# simple operation example of adding, deleting, modifying and querying MongoDB

The current version of the C# driver used by MongoDB is 1.6.0 Download address: https://github.com/mongodb/mongo-csharp-driver/downloads 1, Connect to database 2. Insert data Because MongoDB does not have the concept of a table, you must define your own data model before inserting data User.cs The following is the code for adding data 3. Delete operation 4. Modification 5. Conditional query (simple) 6. Query all

Detailed explanation of Nodejs’ operations of adding, deleting, modifying and checking based on the mongoose module

MongoDB MongoDB is a database based on Javascript language, and the storage format is JSON, and Node is also a Javascript-based environment (library), so the combination of node and mongoDB can reduce the time and space overhead caused by data conversion. Mongoose is an object model tool of MongoDB. It converts data in the database into Javascript objects for use in your application. It encapsulates some common methods of adding, deleting, modifying and checking documents in MongoDB, allowing NodeJS to operate Mongodb database changes. Be more flexible and simple. Install module mongoose npm install mongoose [Note] The mongoose module depends on mongodb npm common commands npm install -g installs the package into the global environment npm install –save When installing, write the information into package.json for later maintenance and viewing. npm remove remove npm update update npm root -g View the global package installation path npm -v View npm version Open mongodb database Enter the directory where mongod is located and execute the command ./mongod –dbpath=the location where the data is stored Example 1: ./mongod –dbpath=../data/dbname Example 2: ./mongod –dbpath=../data/dbname –port Custom port number, default 27017 (just understand it, not recommended, modifying the default port number will cause trouble in…

A framework for adding, deleting, modifying and checking in python_The Django framework in Python cleverly implements adding, deleting, modifying and checking

Django is a very powerful web framework in Python. It has done a lot of things for us and is also packaged in advance. There are many awesome functions that are not too fun to use. In the process of writing a website, we often use the basic functions of adding, deleting, modifying and checking. Django This series of complex logical things are encapsulated into methods “for us to use directly”. The experience during use is so simple that I will give you a simple example to demonstrate. First create a multi-to-one relationship association model We assume there is a topic&# xff0c;There will be a lot of content under the theme,Then we associate the theme and content with the many-to-one ForeignKey field, as follows: # models.py from django.db import models from django.shortcuts import reverse class Topic(models.Model): text = models.CharField ('topic', max_length=100) date_added = models.DateTimeField('added time', auto_now_add=True) class Meta: ordering = ['-date_added'] verbose_name_plural = “Topic” p> def __str__(self): return self.text class Entry(models.Model): topic = models .ForeignKey(Topic, on_delete=models.CASCADE, verbose_name=”Topic”) text = models.TextField('Specific Notes') p> date_added = models.DateTimeField('Add Time', auto_now_add=True) class Meta: ordering & #61; ['-date_added'] verbose_name_plural = “Specific knowledge” def __str__(self): return self.text[:50] + “…” In views.py we use the general display…

mongoose demonstration of adding, deleting, modifying and checking, full version case

mongoose demonstrates addition, deletion, modification and query, full version case 1. Processing dadi/users find create 2. Process dadi/news create find update delete Description: dadi There are users and news tables under the database, which demonstrate addition, deletion, modification and query in detail. 1. Process dadi/users find // 1. Introduce mongooseconst mOngoose= require (‘mongoose’);// 2. Establish a connectionmongoose.connect(‘mongodb://localhost/dadi’, { // Configuration: remove warning message useUnifiedTopology: true, useNewUrlParser: true})// 3. Operate the users table (collection) // Define a Schema. The objects in the schema correspond to the fields in the database one-to-onevar UserSchema = mongoose.Schema({ name: String, age: Number, status: Number,})// 4. Define the database model and operate the database// model Pay attention to the first parameter in it: 1. Capitalize the first letter 2. Establish a connection with the database (collection) name corresponding to this model and the associated database table with the same model namevar User = mongoose.model(‘User ‘, UserSchema);// 5. Query the data of users tableUser.find({}, function(err, doc){ if(err){ console.log(‘ err: ‘, err); return; } console.log(‘doc’, doc);}) create const mOngoose= require(‘mongoose’);mongoose.connect(‘mongodb://localhost/dadi’, { useUnifiedTopology: true , useNewUrlParser: true})var UserSchema = mongoose.Schema({ name: String, age: Number, status: Number,})var User = mongoose.model(‘User’, UserSchema);/** * Add data * 1. Instantiate Modal 2. Instance.save()*/var…

Django life cycle diagram

04. Django framework – static file configuration, initial understanding of request object methods, pycharm link database, ORM practical operation of adding, deleting, modifying and checking, Django request life cycle

Static file configuration We place all HTML files in the templates folder by default Place all static files used by the website in static by default Next Static file File resources that will not automatically change dynamically after writing, such as css files, js files, and pictures we have written files, third-party framework files, we put all static files in a static folder by default. Django will not automatically create a static folder. We need to manually create it ourselves in the django directory. Create this folderUnder normal circumstances, we will further divide the static folder and use it directly: static ├─ bootstrap front-end has been written and can be called directly ├─ js has been writtenjs file ├─ css written css file ├─ img img file used └─ Other third-party file resources The reason why you can see the corresponding resource when you enter the url in the browser is because the developer has already opened an access interface to the resource on the backendIf the resource cannot be accessed, it means that the backend does not have an interface for the resource http://127.0.0.1:8000/static/bootstrap-3.3 .7-dist/css/bootstrap.min.css settings.py static file Configuration # If you want to access static files, you must…

JavaScript usage examples for adding, deleting, modifying and checking web page nodes_javascript skills

JavaScript usage examples for adding, deleting, modifying and checking web page nodes_javascript skills

This article describes the use of Javascript for adding, deleting, modifying and checking web page nodes. Share it with everyone for your reference. The specific analysis is as follows: 1. Basic concepts This part is the so-called “HTML DOM”. The so-called HTML DOM is the Web page loading rule. It is a rule, which is the basic formula for the composition of a web page. That is, all web pages must be written according to the rules of:… and loaded according to such rules. The so-called “web page node” is also called the popular explanation of “DOM node”. For example, the content under the html node is all the content between them, and the content under the body node is all the content between them. HTML DOM is stipulated as follows: 1. The entire document is a document node; 2. Each HTML tag (meaning html tags such as , not just tags) is an element node; 3. Contained in The text in HTML elements is text nodes; 4. Each HTML attribute is an attribute node For example, a page can be drawn as the following DOM node tree: The official definition of HTML DOM is as follows: HTML DOM is…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索