Basic tutorial on operating MongoDB in php (connection, new addition, modification, deletion, query)_php example-php tutorial

The code is as follows: //Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close();

pythonDjango connects to MySQL database for addition, deletion, modification and query

1. Download and install the MySQLdb class libraryhttp://www.djangoproject.com/r/python-mysql/2. Modify settings.py to configure data attributes The code is as follows: DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.mysql’, # Add ‘postgresql_psycopg2’, ‘mysql’, ‘sqlite3’ or ‘oracle’. ‘ NAME’: ‘djangodb’, # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: ‘USER’: ‘root’, ‘PASSWORD’: ‘root ‘, ‘HOST’: ‘127.0.0.1’, # Empty for localhost through domain sockets or ‘127.0.0.1’ for localhost through TCP. ‘PORT’: ‘3306’, # Set to empty string for default. }} After modification, enter DOS and enter the project directory to execute the python manage.py shell command to start the interactive interface and enter the code to verify whether the database configuration is successful. If no error is reported, it is successful! The code is as follows: >> > from django.db import connection>>> cursor = connection.cursor() 3. Create a Django appA project contains One or more such apps. An app can be understood as a collection of functions. For example, the product management module includes functions such as adding, deleting, and checking. Product management can be called an app. Each Django app has independent models, views, etc., which is easy to transplant and reuse. DOS enters the…

Mongodb study notes 2 (simple addition, deletion, checking and modification) – PHP source code

1. Add a piece of data. I also practiced it yesterday and further consolidated it today. There are two main methods, one is save and the other is insert. Example: db.blog.save(({“name”:”taotao”,”address”:{“city”:”beijing”,”post”:”100096″},”phone”:”64645646″})) Or db.blog.insert(({“name”:”taotao”,”address”:{“city”:”beijing”,”post”:”100096″},”phone”:”15210340214″})). In addition, you can assign a value to a variable first and then insert the variable. For examplepost={… “name” : “taotao”,… “address” : {… “city” : “beijing”, … “post” : “100096”… },… “phone” : “15210340214”… }db .blog.insert(post);2. Delete a record db.set name.remove(condition); For example: db.blog.remove({“name”:”ysz”}) delete the name in the set. ysz’s data Delete all records db.set name.remove(); not writing any conditions is equivalent to deleting all data. For example: db.blog.remove();3. Query all records db.set name.find(); For example: db.blog.find(); Find all data in the set lblogQuery all Record db.collection name.findOne(condition); such as: db.blog.findOne({“name”:”ysz”}); find the data with name ysz in the collectionThis is a simple query, learn tomorrow Various query conditions. 4. Modify the record db.setname.update(condition); db.blog.update({“name”:”ysz”}, {“name”:”taotao”}) logically does not write conditions. It should have been all modified, but the actual result was only one modification. This is doubtful at first.

Basic tutorial on operating MongoDB in PHP (connection, new addition, modification, deletion, query)

MongoDB The code is as follows://Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close();

Basic tutorial on operating MongoDB in PHP (connection, new addition, modification, deletion, query)

This article mainly introduces a concise tutorial on operating MongoDB in PHP, including connection, addition, modification, deletion, query, etc. Friends in need can refer to it The code is as follows: //Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close(); ,

MongoDB learning (2) MongoDBJava addition, deletion, query and modification

MongoDB learning (2) MongoDBJava addition, deletion, query and modification

Related information 1. MongoDB for Java driver package https://github.com/mongodb/mongo-java-driver/downloads 2. Online documentation http://www.mongodb.org/display /DOCS/Java+Language+Center Operation 1. Query all data of a certain table (called a collection in MongoDB) Java code DBTest.java pack Related information 1. MongoDB for Java driver package  https://github.com/mongodb/mongo-java-driver/downloads 2. Online documentation http://www.mongodb.org/display/DOCS/Java+Language+Center Operation 1. Query all data in a certain table (called a collection in MongoDB) Java code DBTest.java package com.archie.mongodb; import java.net.UnknownHostException; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.Mongo; import com.mongodb.MongoException; /** * Query all data in the specified DBCollection collection of the specified database * @author archie2010 * * since 2012-9-29 10:40:21 pm */ public class DBTest { public static void main(String[] args) throws UnknownHostException, MongoException { /** A Mongo instance represents a database connection pool * Mongo mg = new Mongo(“localhost”); Mongo mg = new Mongo(“localhost”, 27017); */ Mongo mg = new Mongo(); // Get the database object named “dbtest” DB db = mg.getDB(“dbtest”); // Query all collections in the library (equivalent to tables) for (String name : db.getCollectionNames()) { System.out.println(“Collection Name: ” + name); } DBCollection users = db.getCollection(“emp”); // Query all data in the collection DBCursor cur = users.find(); System.out.println(“Record Count:” + cur.count()); while (cur.hasNext()) { DBObject object =…

mongodb basic addition, deletion, modification and query

To learn a database, the first thing you need to know is how to connect to the database, how to perform basic additions, deletions, modifications and queries, and you can learn other advanced functions slowly. The following mainly explains the basic addition, deletion, modification and query of mogodb 1. Create a database: use mkyongdb (jump to this database if there is one, create and jump if not) Display all databases: show dbs 2. Create a collection ( To learn a database, the first thing you need to know is how to connect to the database, how to perform basic additions, deletions, modifications and queries, and you can learn other advanced functions slowly. The following mainly explains the basic addition, deletion, modification and query of mogodb 1. Create a database: use mkyongdb (if there is one, jump to this database, if not, create and jump) Show all databases: show dbs 2. Create a collection (equivalent to a table in a relational database): Collection operations: (1) Insert data db.users.insert({‘name’:’xumingxiang’,’sex’:’man’}) creates a collection of users Show all collections under the current database: show collections Display all data documents under the users collection: db.users.find() Display the number of records in the collection: db.users.count() (2)…

Java operation mongodb: basic addition, deletion, modification and query

Java code for operating mongodb, including basic add, delete, modify and query operations to obtain the database connection tool class package com.liuc.db;import java.net.UnknownHostException;import com.mongodb.DB;import com. mongodb.DBCollection;import com.mongodb.Mongo;/** * * @brief MongoDBUtil.java operation Java code for operating mongodb, including basic add, delete, modify and query operations Get the database connection tool class package com.liuc.db; import java.net.UnknownHostException; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.Mongo; /** * * @brief MongoDBUtil.java operating mongodb tool class * @attention Notes on usage * @author liuchao * @date 2013-12-30 * @note begin modify by Modifier Modification time Summary of modification content */ public class MongoDBUtil { /** * * \brief Obtain database connection without authentication * @return * Precautions for using @attention method * @author liuchao * @date 2013-12-30 * @note begin modify by Modifier Modification time Summary of modification content */ public static DBCollection getDBConnectionWithoutAuth(String colName){ try { Mongo mOngo= new Mongo(“localhost”, 27017); DB db = mongo.getDB(“liuchao”); return db.getCollection(colName); } catch (UnknownHostException e) { e.printStackTrace(); return null; } } /** * Obtain the database connection that requires authentication Start login password authentication: Log in to the database and add users use db.addUser('user1','pwd1'); Restart the server and enable the authentication service mongod –auth –dbpath=D:\mongodb\db Next, you will need…

MongoDB (6) java operation mongodb addition, deletion, modification and query

We already know the code of Java operating mysql database very well, such as addition, deletion, modification and query. Java also performs similar operations on mongodb database. First, connect to the database, and then perform operations. First, we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because users can java operate the mysql database code. We already know everything about it, adding, deleting, modifying, and checking. Java also performs similar operations on the mongodb database. The database is connected first, and then the operation is performed. First we enter the admin database, and then create our own database testMongoDb. After entering the admin database, we can directly enter testMongoDb, because users can enter the system database and are super administrators. After use testMongoDb, Set the user name and password for the database, db.addUser('root','root'), so that we can connect to the database in the program and implement additions, deletions, modifications and queries. The code is as follows. package com.mkyong.core; import java.net.UnknownHostException; import java.util.Date; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import com.mongodb.DBCursor; import com.mongodb.Mongo; import com.mongodb.MongoException; /** * Java + MongoDB Hello world Example * */ public class App…

Basic tutorial on operating MongoDB in PHP (connection, new addition, modification, deletion, query)_php example

The code is as follows: //Connect localhost:27017$cOnn= new Mongo(); //Default port for connecting to the remote host$cOnn= new Mongo(‘test.com’); //Connect to the remote host port 22011$cOnn= new Mongo(‘test.com:22011’); //MongoDB has a username and password$cOnn= new Mongo(“mongodb://${username}:${password}@localhost”) //MongoDB has a username and password and specifies the database blog$cOnn= new Mongo(“mongodb://${username}:${password}@localhost/blog”); //Multiple servers$cOnn= new Mongo(“mongodb://localhost:27017,localhost:27018”);//Select database blog$db = $conn-> blog;//Specify the result set (table name: users)$collection = $db->users;//Newly added$user = array(‘name’ => ‘caleng ‘, ’email’ => ‘admin#admin.com’);$collection->insert($user);//Modify$newdata = array(‘$set’ => array (“email” => “[email protected]”));$collection->update(array(“name” => “caleng”), $newdata);//Delete $collection->remove(array(‘name’=>’caleng’), array(“justOne” => true));//Find$cursor = $collection->find();var_dump($cursor);//Find one$user = $collection->findOne(array(‘name’ => ‘caleng’), array(’email’)); var_dump($user);//Close the database$conn->close();

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
首页
微信
电话
搜索