Geen cache-versie.


Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher une fonction PHP

MongoDB::createCollection

(PECL mongo >=0.9.0)

MongoDB::createCollectionCreates a collection

Description

public MongoDB::createCollection ( string $name [, array $options ] ) : MongoCollection

This method is used to create capped collections and other collections requiring special options. It is identical to running:

<?php

$collection 
$db->command(array(
    
"create" => $name,
    
"capped" => $options["capped"],
    
"size" => $options["size"],
    
"max" => $options["max"],
    
"autoIndexId" => $options["autoIndexId"],
));

?>
See MongoDB::command() for more information about database commands.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Parameters

name

The name of the collection.

options

An array containing options for the collections. Each option is its own element in the options array, with the option name listed below being the key of the element. The supported options depend on the MongoDB server version and storage engine, and the driver passes any option that you give it straight to the server. A few of the supported options are, but you can find a full list in the MongoDB core docs on » createCollection:

capped

If the collection should be a fixed size.

size

If the collection is fixed size, its size in bytes.

max

If the collection is fixed size, the maximum number of elements to store in the collection.

autoIndexId

If capped is TRUE you can specify FALSE to disable the automatic index created on the _id field. Before MongoDB 2.2, the default value for autoIndexId was FALSE.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Return Values

Returns a collection object representing the new collection.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Examples

Example #1 MongoDB::createCollection() capped collection example

A capped collection is a special type of collection that has either a fixed or a fixed number of elements. Once the collection is "full," the oldest elements will be removed when new elements are added. Capped collections can be very useful for applications like logging, where you may want to reserve a certain amount of space for logs and not worry about them getting too big.

This example creates a very tiny log collection that will keep a maximum of 10 documents.

<?php

$log 
$db->createCollection(
    
"logger",
    array(
        
'capped' => true,
        
'size' => 10*1024,
        
'max' => 10
    
)
);

for (
$i 0$i 100$i++) {
    
$log->insert(array("level" => WARN"msg" => "sample log message #$i""ts" => new MongoDate()));
}

$msgs $log->find();

foreach (
$msgs as $msg) {
    echo 
$msg['msg']."\n";
}

?>

The above example will output something similar to:


sample log message #90
sample log message #91
sample log message #92
sample log message #93
sample log message #94
sample log message #95
sample log message #96
sample log message #97
sample log message #98
sample log message #99

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Changelog

Version Description
1.4.0

In versions before 1.4.0, the options were all arguments to the method. The function synopsis in those older versions is:

public MongoDB::createCollection ( string $name [, bool $capped = FALSE [, int $size = 0 [, int $max = 0 ]]] ) : MongoCollection

The meaning of the options is the same as described under the options argument above.

Zoek een PHP-functie

Vertaling niet beschikbaar

De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.

Als je de moed voelt, kun je je vertaling aanbieden ;-)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-mongodb.createcollection.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : http://php.net

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut