insert() public method

Direct insert of array to MongoDB without creating document object and validation
public insert ( array $document ) : Collection
$document array
return Collection
Example #1
0
 public function testInsert_Unacknowledged()
 {
     $this->collection->setUnacknowledgedWriteConcern();
     $this->collection->insert(array('a' => 1, 'b' => 2));
     $document = $this->collection->find()->where('a', 1)->findOne();
     $this->assertNotEmpty($document);
     $this->assertEquals(2, $document->b);
 }
Example #2
0
 public function testHint()
 {
     // create index
     $this->collection->ensureIndex(array('a' => 1));
     $this->collection->ensureIndex(array('a' => 1, 'b' => 1));
     // add documents
     $this->collection->insert(array('a' => 1))->insert(array('a' => 1, 'b' => 1));
     // without hint
     $explainWithoutHint = $this->collection->find()->where('a', 1)->explain();
     // with hint
     $explainWithHint = $this->collection->find()->hint(array('a' => 1, 'b' => 1))->where('a', 1)->explain();
     $currentVersion = $this->collection->getDatabase()->getClient()->getDbVersion();
     if (version_compare($currentVersion, '3', '<')) {
         $this->assertEquals('BtreeCursor a_1', $explainWithoutHint['cursor']);
         $this->assertEquals('BtreeCursor a_1_b_1', $explainWithHint['cursor']);
     } else {
         $this->assertEquals('a_1', $explainWithoutHint['queryPlanner']['winningPlan']['inputStage']['indexName']);
         $this->assertEquals('a_1_b_1', $explainWithHint['queryPlanner']['winningPlan']['inputStage']['indexName']);
     }
 }