Рекурсивный акроним словосочетания «PHP: Hypertext Preprocessor»
Добро пожаловать на форум PHP программистов!
За последние 24 часа нас посетили 17918 программистов и 1567 роботов. Сейчас ищут 1005 программистов ...
Adding Multiple Documents
Вернуться к: Tutorial
In order to do more interesting things with queries, let's add multiple simple documents to the collection. These documents will just be of the form array( "i" => value ); and we can do this fairly efficiently in a loop:
<?php
$connection = new MongoClient();
$collection = $connection->database->collectionName;
for ( $i = 0; $i < 100; $i++ )
{
$collection->insert( array( 'i' => $i, "field{$i}" => $i * 2 ) );
}
?>
Notice that we can insert arrays with different keys into the same collection. This aspect is what we mean when we say that MongoDB is "schema-free". In the example above each document has an i field, but also a field name in the form of field + $i.
Вернуться к: Tutorial