Several minor issues about MongoDB insert

Source: Internet
Author: User

Collections collection: insert (Array $ [, Array $ Options = Array ()])

Use of the second parameter of this method

'Safe ': Specifies a Boolean OR integer. The default value is false. If it is falseProgramWill continue, without waiting for the database response. That is, the program will not be interrupted no matter whether the data is successfully inserted.

'Fsync': The default value is false. If it is true, data is forcibly synchronized to the disk. The previous 'safe 'setting overwrites false.
PS: When I used MongoDB, I encountered a process that was inserted into the database, and another process could not read data immediately. It turns out that MongoDB may not insert data to the disk immediately.

'Timeout': Set the timeout value.

If the second parameter of this method is set to true only, the following is the case:
$ Mongo = new Mongo ("192.168.8.249: 27017 ");
$ Conn = $ mongo-> test-> Table1;
$ DATA = array (....);
$ Conn-> insert ($ data, true );

We set the safe parameter to true by default.

========================================================== ========================

About Indexes

<? PHP
$ Mongo = new Mongo ("192.168.8.249: 27017 ");
$ Conn = $ mongo-> test-> table;
$ Conn-> ensureindex (Array ("A" => 1, "B" => 1 ));

$ Award = array (
'A' => array (1 ),
'B' => array (2 ),
);

$ Conn-> insert ($ Award, true );

If we create a joint index, when inserting data, the two fields of the index are arrays, and the following error is returned.
"Cannot index parallel arrays"

 

Therefore, the fields of the joint index cannot be arrays.

Related Article

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.