Installation and configuration of Mangodb

Source: Internet
Author: User

1. Installation official: https://www.mongodb.org/dl/linux/x86_64-rhel62 Our download of MongoDB is the community version, has helped us compile well, so we do not need to compile here, We simply unzip the downloaded file and move it to the installation directory, for example: Move to/usr/local/mongodb. Show dbs/show Databases view database show Tables/show collections View list of tables use TableName switch database db.help () View command Help Db.tableName.drop () Delete the TableName table, tableName the table name Db.dropdatabase () delete the currently switched database Db.createcollection (tableName) CREATE TABLE Implicit add: If the subordinate structure is added, Then the parent structure is automatically added. For example: I created a table under a nonexistent database and the database is created automatically. Data tables also support the implicit creation of Insert data Db.tableName.insert () Example 1: Insert a Db.user.insert ({' name ': ' Shusheng '}) into the user table Db.user.insertOne ({' Name ': ' Shusheng '}) Example 2: Insert multiple Db.user.insert into user table ([{' Name ': ' Guo Changsong ', ' age ': 20},{' name ': ' Li Zhiyou ', ' Girl ': [' Warren, Li Zhiguang ']}]) Db.user.insertMany ([{' Name ': ' Guo Changsong ', ' age ': 20},{' name ': ' Li Zhiyou ', ' Girl ': [' Warren, Li Zhiguang ']}]) query data db.tableName.find (where) Where: query criteria, optional
Operation Format Example Similar statements in an RDBMS
Equals {<key>:<value>} Db.col.find ({"By": "Rookie Tutorial"}). Pretty () where by = ' Rookie Tutorial '
Less than {<key>:{$lt: <value>}} Db.col.find ({"likes": {$lt:). Pretty () Where likes < 50
Less than or equal to {<key>:{$lte: <value>}} Db.col.find ({"likes": {$lte:). Pretty () where likes <= 50
Greater than {<key>:{$gt: <value>}} Db.col.find ({"likes": {$gt:). Pretty () where likes > 50
Greater than or equal to {<key>:{$gte: <value>}} Db.col.find ({"likes": {$gte:). Pretty () where likes >= 50
Not equal to {<key>:{$ne: <value>}} Db.col.find ({"likes": {$ne:). Pretty () where likes! = 50
  Example 1:db.member.find ({name: ' Baba '}) query name= ' Baba ' records   example 2:db.member.find ({name: ' Baba ', age:30}) query Name= ' Baba ' and age=30 Records   Example 3:db.member.find ({age:{$lt: 26}) query for records with age less than 26   example 4:db.member.find ({age:{$lt: $gt: 20 }) query for records with age greater than 20 less than 26: Show query Results Db.tableName.find (where) in a formatted structure. Pretty ()   Delete data Db.member.remove ( Where,justone) Where: deleted conditional expression Justone: When there are multiple entries for a qualified document, only one record is deleted for true, false means delete all, default is false  Basic syntax for updating data: Db.tableName.update (Where,data,upsert,multi) Where: conditional expression (updated condition) data: Upsert to update: TRUE Indicates that if a record cannot be found based on a query criteria expression, the data that is prepared for updating is inserted into the table as a new record, by default, Falsemulti: false, which means that only one record that meets the criteria is updated, and if true, indicates that all eligible records are updated. This parameter must be in effect with the $ operation only   example data preparation: Db.member.insert ({name: ' Baba ', Age:30,sex: ' Male ', ' money ': 999999999})   by default, Update overwrites the entire document (entire record content) example 1:db.member.update ({name: ' Baba '},{' money ': 99999999998}) After performing the above operation, the entire record becomes: {' Money ' :99999999998}  only changes the partial field value db.tableName.update (conditional expression, {$set: Modified content}) example 2:db.member.update ({name: ' Baba '},{$set: {' Money ': 99999999998}}) after performing the above operation, the entire record will become: {name: ' Baba ', Age:30,sex: ' Male ', ' money ':99999999998}  Example 3: Use example of the third parameter db.member.update ({name: ' Bingbing '},{name: ' libingbing ', age:40},true) if it is based on {name: ' Bingbing '} could not find a qualifying record, insert {name: ' libingbing ', age:40} into the datasheet as a new record.   Example 4: The fourth parameter uses the correct method: Db.member.update ({name: ' small pot '},{$set: {name: ' hotpot ', age:3}},false,true) Error usage: db.member.update ({name: ' small pot '},{name: ' hotpot ', age:3},false,true)   php operation mongodb  Extension address:/HTTP Pecl.php.net/package/mongo Document: http://php.net/manual/zh/class.mongoclient.php User: http://www.runoob.com/mongodb/ mongodb-php.html link "Php7mongdb Installation and use:http://www.runoob.com/mongodb/php7-mongdb-tutorial.html   MongoDB additions and deletions to search:

<?php

$manager = new Mongodb\driver\manager ("mongodb://127.0.0.1:27017");
Print_r ($manager);

Inquire
/*
Query criteria
$filter = ["Name" = ' Shuaige '];
$query = new Mongodb\driver\query ($filter);
$cursor = $manager->executequery (' Yyy.user ', $query);

foreach ($cursor as $document) {
Print_r ($document);
}
*/


Inserting data
/*
$bulk = new Mongodb\driver\bulkwrite;
$bulk->insert ([' name ' = ' zzz ', ' age ' =>18]);
$bulk->insert ([' name ' = ' zsy ', ' age ' =>17]);

$res = $manager->executebulkwrite (' Yyy.user ', $bulk);
Print_r ($res);
*/

Update
/*
$bulk = new Mongodb\driver\bulkwrite;
$bulk->update ([' name ' = ' zzz '],[' $set ' =>[' girl ' = ' LYF ']]);
$writeConcern = new Mongodb\driver\writeconcern (mongodb\driver\writeconcern::majority, 1000);
$result = $manager->executebulkwrite (' Yyy.user ', $bulk, $writeConcern);

Print_r ($result);
*/

Delete
$bulk = new Mongodb\driver\bulkwrite;
$bulk->delete ([' name ' = ' shuaige ']);
$writeConcern = new Mongodb\driver\writeconcern (mongodb\driver\writeconcern::majority, 1000);
$result = $manager->executebulkwrite (' Yyy.user ', $bulk, $writeConcern);
Print_r ($result);

Service startup for Mangodb:

./bin/mongod--dbpath=/usr/local/mongodb/data/--logpath=/usr/local/mongodb/logs/log--bind_ip=0.0.0.0--fork

Installation and configuration of Mangodb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.