Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-1145

Add helper method Collection::create(array $options)

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Collection Management
    • None

      Proposition to add a method Collection::create(array $option) as a helper for Database::createCollection() for consistency with Collection::drop(array $options)

       

      Usage:

      // Existing methods
      $db->createCollection('items', ['capped' => true, 'size' => 8192]);
      $db->dropCollection('items');
      $db->items->drop();
      
      // New method
      $db->items->create(['capped' => true, 'size' => 8192]);

      Historically, collections are created from the parent database object. The driver API is based on the MongoDB shell, which only has a db.createCollection() method. The drop() methods are a different case, since the shell provides drop methods on both databases and collections (instead of requiring you to call client.dropDatabase or database.dropCollection). There's no technical reason we can't duplicate a create helper on the collection object. 

      private slack

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: