#./mongod
2018-04-15t18:52:36.352+0800 i control [initandlisten] mongodb starting : pid=36578 port=27017 dbpath=/data/db 64-bit host= Ibg-opensource-db-cwt132018-04-15t18:52:36.352+0800 i control [initandlisten] db version v3.6.22018-04-15t18:52:36.352+0800 i control [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c5394202018-04-15t18:52:36.352+0800 i control [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 20132018-04-15t18:52:36.352+0800 i control [initandlisten] allocator: tcmalloc2018-04-15t18:52:36.352+0800 i control [initandlisten] modules: None2018-04-15t18:52:36.352+0800 i control [initandlisten] build environment : 2018-04-15t18:52:36.352+0800 i control [initandlisten] distmod: rhel702018-04-15t18:52:36.352+0800 i control [initandlisten] distarch: x86_642018-04-15t18:52:36.352+0800 i control [initandlisten] target_arch: x86_642018-04-15t18 : 52:36.352+0800 i control [initandlisten] options: {}2018-04-15t18:52:36.354+ 0800 i - [initandlisten] detected data files in /data/db created by the ' Wiredtiger ' storage engine, so setting the active storage engine to ' Wiredtiger '. 2018-04-15t18 : 52:36.354+0800 i storage [initandlisten] wiredtiger_open config: create, Cache_size=7423m,session_max=20000,eviction= (threads_min=4,threads_max=4), config_base=false,statistics= (FAST), Log= (Enabled=true,archive=true,path=journal,compressor=snappy), file_manager= (close_idle_time=100000), statistics_log= (wait=0), verbose= (Recovery_ Progress),2018-04-15t18:52:36.512+0800 i storage [initandlisten] wiredtiger Message [1523789556:512963][36578:0x7f6aac8c2b00], txn-recover: main recovery loop: starting at 2/350722018-04-15t18:52:36.615+0800 i storage [initandlisten] WiredTiger message [1523789556:615462][36578:0x7f6aac8c2b00], txn-recover: recovering log 2 through 32018-04-15t18:52:36.676+0800 i storage [ Initandlisten] wiredtiger message [1523789556:676715][36578:0x7f6aac8c2b00], txn-recover: Recovering log 3 through 32018-04-15T18:52:36.740+0800 I CONTROL [initandlisten] 2018-04-15t18:52:36.740+0800 i control [initandlisten] ** warning: access control is not enabled for the database.2018-04-15t18:52:36.740+0800 i Control [initandlisten] ** read and write access to data and configuration is Unrestricted.2018-04-15t18:52:36.740+0800 i control [initandlisten] ** warning: You are running this process as the root user, which is not recommended.2018-04-15t18:52:36.740+0800 i control [initandlisten] 2018-04-15t18:52:36.740+0800 i control [initandlisten] ** warning: this server is bound to localhost.2018-04-15T18:52:36.740+0800 I CONTROL [initandlisten] ** remote systems will be unable to connect to this server. 2018-04-15t18:52:36.740+0800 i control [ Initandlisten] ** start the server with --bind_ip <address> to specify which ip 2018-04-15t18 :52:36.740+0800 i control [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to2018-04-15t18:52:36.740+0800 i control [initandlisten] ** bind to all interfaces. if this behavior is desired, start the2018-04-15T18:52:36.740+0800 I Control [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.2018-04-15t18:52:36.740+0800 i control [initandlisten] 2018-04-15T18:52:36.741+0800 I CONTROL [initandlisten] 2018-04-15t18:52:36.741+0800 i control [initandlisten] ** warning: /sys/ kernel/mm/transparent_hugepage/defrag is ' always '. 2018-04-15t18:52:36.741+0800 i control [initandlisten] ** We suggest setting it to ' Never ' 2018-04-15t18:52:36.741+0800 i control [initandlisten ] 2018-04-15t18:52:36.741+0800 i control [initandlisten] ** warning: soft rlimits too low. rlimits set to 65535 processes, 655350 files. number of processes should be at least 327675 : 0.5 times number of files.2018-04-15t18:52:36.741+0800 i control [initandlisten] 2018-04-15t18 : 52:36.755+0800 i ftdc [initandlisten] initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data ' 2018-04-15t18 : 52:36.756+0800 i network [initandlisten] waiting for connections on port 27017
#./mongo
mongodb shell version v3.6.2connecting to: mongodb://127.0.0.1:27017mongodb server version: 3.6.2server has startup warnings: 2018-04-15t11:01:19.795+0800 I CONTROL [initandlisten] 2018-04-15T11:01:19.795+0800 I CONTROL [initandlisten] ** warning: access control is not enabled for the database.2018-04-15t11:01:19.795+0800 i control [initandlisten] ** Read and write access to Data and configuration is unrestricted.2018-04-15t11:01:19.795+0800 i control [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.2018-04-15t11:01:19.795+0800 i control [initandlisten] 2018-04-15t11:01:19.795+0800 i control [initandlisten] ** Warning: this server is bound to localhost.2018-04-15t11:01:19.795+0800 i CONTROL [initandlisten] ** remote systems will be unable to connect to this server. 2018-04-15t11:01:19.795+0800 i control [initandlisten] ** Start the server with --bind_ip <address> to specify which ip 2018-04-15t11:01:19.795+0800 i control [ initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to2018-04-15t11:0 1:19.795+0800 i control [initandlisten] ** bind to all interfaces. if this behavior is desired, start the2018-04-15t11:0 1:19.795+0800 i control [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.2018-04-15t11:01:19.795+0800 i control [initandlisten] 2018-04-15t11:0 1:19.796+0800 i control [initandlisten] 2018-04-15t11:01:19.796+0800 i control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/defrag is ' Always ' .2018-04-15t11:01:19.796+0800 i control [initandlisten] ** We suggest setting it to ' Never ' 2018-04-15t11:01:19.796+0800 i contrOl [initandlisten] 2018-04-15t11:01:19.796+0800 i control [initandlisten] ** warning: soft rlimits too low. rlimits set to 65535 processes, 655350 files. Number of processes should be at least 327675 : 0.5 times number of files.2018-04-15t11:01:19.796+0800 I control [initandlisten]
https://docs.mongodb.com/manual/reference/method/db.collection.insert/
First, insert the document
Insert Behavior, if the collection does not exist, creates a
Collection Creation:
If The collection does not currently exist, insert operations would create the collection.
Method:
Db.collection.insertOne (<document>, {writeconcern: <document>//optional. A document expressing the write concern. Omit to use the default write concern. })
Attention:
The operation creates a collection if the collection does not exist.
This operation does not support Db.collection.explain () query plans can use Insert instead.
_id Field:
If The document does not specify a _id field, MongoDB adds the _id field with a ObjectId value to the new document.
The Objectid value is made up of 12 bytes, with the first four bytes reflecting the timestamp created by Objectid, as follows:
A 4-byte value representing the seconds since the Unix epoch,
A 3-byte machine identifier,
A 2-byte process ID, and
A 3-byte counter, starting with a random value.
> Db.products.insertOne ({item: "Card", qty:15});
{"acknowledged": true, return value "Insertedid": ObjectId ("5ad2c1572c23d0642cd35b48")}> db.products.find (); {"_id": ObjectId ("5ad2c1572c23d0642cd35b48"), "Item": "Card", "Qty": 15}
> Db.products.insertOne (
{"Item": "Envelopes", "Qty": +, type: "Self-sealing"},
{writeconcern: {w: "Majority", wtimeout:100}}//w:majority, which indicates that the >1/2 node has data
)
{"acknowledged": true, "Insertedid": ObjectId ("5ad2cecd2c23d0642cd35b4c")}
Db.collection.insertMany ({[<document 1>, <document 2>, ...]},//an array of documents to inserts into th E collection. Note the array {writeconcern: <document>, ordered: <boolean>//optional. A Boolean specifying whether the Mongod instance should perform an ordered or unordered insert. Defaults to True. The default order added in order is slower than adding it in order)
Attention:
Each set of operations can have up to 1000 documents.
The order is added at a slower rate than is added in order.
Collections that do not exist are created automatically.
Insertmany () also does not support Db.collection.explain () can use Insert instead.
If an error is added, the bulkwriteerror exception exception is reported, and an operation that is added sequentially encounters an error that stops directly, but does not sequentially continue the write operation in the queue.
> Db.products.insertMany ([
{item: "Card", qty:15},
{item: "Envelope", qty:20},
{Item: "Stamps", qty:30}
], {w: "Majority", wtimeout:100}
);
{"acknowledged": true, "Insertedids": [ObjectId ("5ad2c2332c23d0642cd35b49"), ObjectId ("5ad2c2332c23d0642cd35b4a"), ObjectId ("5ad2c2332c23d0642cd35b4b")]}
Db.collection.insert (#同时又insertOne and Insertmany functions <document or array of documents>,//arrays or documents can be added {write Concern: <document>, ordered: <boolean>//Follow Insertmany () action})
Db.products.insert ([
{item: "Card", qty:15},
{item: "Envelope", qty:20},
{Item: "Stamps", qty:30}
], {w: "Majority", wtimeout:100}
);
Db.products.insert ({item: "Card", qty:40});
Additional Methods for Inserts
When used with the Upsert:true option: The following method creates a new document when no query criteria match, the default is False.
Db.collection.update () Db.collection.updateOne () Db.collection.updateMany () Db.collection.findAndModi FY () db.collection.findOneAndUpdate () Db.collection.findOneAndReplace () Db.collection.save () Db.collection.bulkWrite ()
MongoDB CRUD Operations