Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ Introduction and MongoDB CRUD     - Simple steps allows you to build a more secure Linux server (Linux)

- Install Unity 8 preview version of the desktop in Ubuntu (Linux)

- Use a soft Raid play multiple SSD hard drive performance and enhance data security (Linux)

- CentOS 6.5 installation using a data recovery software extundelete (Linux)

- Debian 7 and Debian 8 users how to install Oracle Java 8 (Linux)

- C ++ you can become a new scripting language (Programming)

- CentOS 6.5_x64 install Oracle 11g R2 (Database)

- Linux PXE unattended installation PXE-E32: TFTP OPen timeout the solution (Linux)

- Glibc support encryption by modifying the DNS (Programming)

- Python Basics Tutorial - lambda keyword (Programming)

- Using Linux command line and execute PHP code (Programming)

- floating IP in OpenStack neutron (Server)

- Getting Started with Java NIO (Programming)

- Zabbix monitoring of the switch (Server)

- Update GAMIT10.6 command (Linux)

- Oracle multi-table query optimization (Database)

- Linux processes in memory and memory cgroup statistics (Linux)

- Linux using TCP-Wrapper Service Management (Linux)

- Ubuntu users Steam controller does not work solutions (Linux)

- Linux, see picture not resolve the problem (Linux)

 
         
  Introduction and MongoDB CRUD
     
  Add Date : 2018-11-21      
         
         
         
  I. Introduction

MongoDB is a C ++ language, is based on a distributed file storage system open source database. MongoDB is designed to provide scalable, high-performance data storage solutions WEB applications. MongoDB stores data as a document data structure by a key (key => value) pairs. MongoDB document similar to the JSON object. Field value can contain other documents, arrays and array of documents.

mongodb Data Type:

Data Type Description
String string. Storing data commonly used data types. In MongoDB, UTF-8 encoded string is legal.
Integer Integer values. It used to store values. Depending on the server you are using, it can be divided into 32-bit or 64-bit.
Boolean Boolean value. For storing Boolean values ​​(true / false).
Double double-precision floating-point values. For storing floating-point values.
Min / Max keys value and the minimum value of a BSON (binary JSON) element and the highest value of the relative ratio.
Arrays for array or list or store multiple values ​​for a key.
Timestamp timestamp. Modify or add records document the specific time.
Object for the embedded documents.
Null is used to create a null value.
Symbol symbol. This data type is substantially equal to the string type, but the difference is that it is generally for the use of special symbols typed language.
Date Date Time. UNIX time format used to store the current date or time. You can specify your own date and time: Date object is created, the incoming date information.
Object ID Object ID. ID used to create the document.
Binary data Binary Data. For storing binary data.
Code Code Type. JavaScript code is used to store documents.
Regular expression Regular expression types. For storing the regular expression.
II. Operation

1, the database manipulation instruction

(1) Create a database

Command: use dbname, Example: use test if the selected test database test database exists, if it does not exist to create a database test.

(2) View all databases

Command: show dbs

(3) Delete the database

Command: db.dropDatabase () to delete the current database

2, the document operation instruction

mongodb a document equivalent to a data structure BSON relational database row, and JSON document basically the same.

(1) into a document

MongoDB using the insert () or save () method to insert a document to the collection, the syntax is as follows: db.COLLECTION_NAME.insert (document).

Example: db.mycol.insert ({name: 'test1', age: 20, sex: 'male'}), which is a collection of mycol name, if the collection does not exist mongodb will be created automatically.

You can also use db.COLLECTION_NAME.save (document) into a document, similar to insert, if you specify the _id field then update the document _id.

(2) update the document

mongodb update using update or save a document, update the syntax:

db.collection.update (
  ,
  ,
  {
    upsert: ,
    multi: ,
    writeConcern:
  }
)

query: update query criteria;

update: update objects and some of the newer operators (such as $, $ inc ...), etc., can also be understood within the sql update query behind the set;

upsert: optional, meaning this argument is that if there is no record update, is inserted objNew, true to insert, the default is false, not inserted.

multi: Optional, mongodb default is false, only to find the first record to update, if this argument is true, according to the conditions put out many records check all the updates.

writeConcern: optional level exception is thrown.

Example: First insert a document: db.mycol.insert ({name: 'test1', age: 1, sex: 'male'}), and then perform the update operation: db.mycol.update ({ 'name': ' test1 '}, {$ set: {' sex ':' formale '}}) were as follows:



If you need to modify the qualifying number of documents put the multi set to true. Example: db.mycol.update ({ 'name': 'test1'}, {$ set: { 'sex': 'formale'}}, {multi: true})

save method: to replace existing documents by incoming documents. Syntax is as follows:

db.collection.save (
  ,
  {
    writeConcern:
  }
)

document: the document data, writeConcern: thrown level.

(3) delete the document

mongodb use db.col.remove () to remove the document, grammatical structure is as follows (before version 2.6):

db.collection.remove (
  ,
  
)

After the 2.6 release:

db.collection.remove (
  ,
  {
    justOne: ,
    writeConcern:
  }
)

query (Optional): Conditions deleted, justOne (optional): If set to true or delete only a 1, writeConcert (optional): level exception is thrown.

Example: db.mycol.remove ({ 'name': 'test1'})

(3) query document

db.COLLECTION_NAME.find () method to display all unstructured data, db.COLLECTION_NAME.find (). pretty () method to display all formatted data. In addition there findOne () method to display only one document.

mongodb relational database where the comparison:

Examples RDBMS format operation of similar statements
Equal to {: } db.col.find ({ "by": "rookie Tutorial"}). Pretty () where by = 'rookie tutorial'
Less than {: {$ lt: }} db.col.find ({ "likes": {$ lt: 50}}). Pretty () where likes <50
Less than or equal to {: {$ lte: }} db.col.find ({ "likes": {$ lte: 50}}). Pretty () where likes <= 50
Greater than {: {$ gt: }} db.col.find ({ "likes": {$ gt: 50}}). Pretty () where likes> 50
Greater than or equal to {: {$ gte: }} db.col.find ({ "likes": {$ gte: 50}}). Pretty () where likes> = 50
It is not equal to {: {$ ne: }} db.col.find ({ "likes": {$ ne: 50}}). Pretty () where likes = 50!
mongodb AND conditions: mongodb the find () method can be passed more than one key (key), each key with a comma separated, syntax is as follows:

db.col.find ({key1: value1, key2: value2}). pretty ()

Example: db.mycol.find ({ 'name': 'tes1', 'sex': 'formale'}). Pretty (), an effect similar to the sentence sql: where name = 'test1' and sex = 'formale' ,

mongodb OR condition: MongoDB OR conditional statement uses the keyword $ or, syntax is as follows:

db.col.find (
  {
      $ Or: [
        {Key1: value1}, {key2: value2}
      ]
  }
) .pretty ()
     
         
         
         
  More:      
 
- How to migrate MySQL to MariaDB under linux (Database)
- How to Install Focuswriter 1.4.5 (Linux)
- How to display a dialog Bash Shell script (Programming)
- Incremental garbage collection mechanism for Ruby 2.2 (Programming)
- Use SocketServer write a sockets program (Programming)
- RedHat / CentOS ext4 partition can not be formatted large supplementary ext4 formatting (Linux)
- Docker + OpenvSwitch build experimental environment VxLAN (Server)
- Four IDS intrusion detection tool under Linux environment (Linux)
- Elaborate 10-point difference between the new and malloc (Programming)
- Netfilter / Iptables Comments (Linux)
- Linux System Getting Started Learning: Linux common log file (Linux)
- Exploring the Android Listview display confusion (Programming)
- What Java 8 fastest garbage collector (Programming)
- These days have been tossing in the Linux under the ASP.NET 5, on the next in the other operating systems in the ASP.NET 5 or. NET applications, in order to complete the MS VM (CoreCLR) run is not far Reach, the effect of the application.

Cur
(Server)
- To delete the directory and all specified files under the Mac (Linux)
- Postmodern systems programming language (Programming)
- LVM Disk Manager Application (Linux)
- About Git (Linux)
- Spring + Log4j + ActiveMQ remote logging - Analysis of combat (Server)
- Oracle archive log full cause abnormal slow database performance (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.