The CREATE COLLECTION clause does not have any options, but there are 3 options you can pass which are capped, max, size. See here for a good explanation :
http://www.cs.wcupa.edu/docs/php/mongodb.createcollection.html
"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."
In the Mongo Shell I can do this :>> db.createCollection("app1_log", true, 10*1024, 10)
Other databases like Oracle include storage options like this :
CREATE TABLE HR.COUNTRIES (
COUNTRY_ID CHAR(2) NOT NULL,
COUNTRY_NAME VARCHAR2(40) NULL,
REGION_ID NUMBER NULL,
CONSTRAINT COUNTRY_C_ID_PK PRIMARY KEY(COUNTRY_ID)
NOT DEFERRABLE
USING INDEX
TABLESPACE EXAMPLE PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE( INITIAL 65536 MINEXTENTS 1 MAXEXTENTS 2147483645 BUFFER_POOL DEFAULT )
NOLOGGING
)
NOCOMPRESS
NOPARALLEL
NOCACHE
MONITORING
NOROWDEPENDENCIES
DISABLE ROW MOVEMENT
We should consider adding these 3 options like this :
CREATE COLLECTION [NAME] { CAP | NOCAP } { MAX [AMOUNT] } { SIZE [AMOUNT] }
For the system catalog/show command looks like we can tell if the collection is capped, but not sure if we can tell the MAX and SIZE. Would be nice if we could tell and show it in the Detail View for the Collections folder node of the tree.
Doesn't look like you can ALTER the options once created.
Looks like you might be able to change the storage options : capped collections
You can convert a non-capped collection to a capped collection with the convertToCapped command:
db.runCommand({"convertToCapped": "mycoll", size: 100000});
http://api.mongodb.org/java/2.10.1/com/mongodb/DB.html#createCollection(java.lang.String, com.mongodb.DBObject) - this supports the capped (as a boolean), size and max.
Assigning to Jenny to define the SQL Syntax and the enhancements needed from Emil.
http://api.mongodb.org/java/2.10.1/com/mongodb/DB.html#createCollection(java.lang.String, com.mongodb.DBObject) - this supports the capped (as a boolean), size and max.
Assigning to Jenny to define the SQL Syntax and the enhancements needed from Emil.
Emil, please implement the following SQL changes. When you are done, re-assign this issue back to me and I'll then implement the ADS changes.
CREATE COLLECTION collection_name [ CAPPED { true | false } ] [ SIZE sizeInBytes ] [ MAX_CAP numOfDocuments ]
- Default for CAPPED is false.
- If CAPPED is true, SIZE is the maximum size in bytes for the capped collection.
- If CAPPED is false, SIZE is optional and it specifies the size to preallocate space for the collection.
- MAX_CAP is optional. If CAPPED is true, it specifies a maximum "cap," in number of documents.
ALTER COLLECTION collection_name CAPPED SIZE sizeInBytes
- This command converts a non-capped collection to a capped collection.
Also, update the SHOW COLLECTIONS command and the TABLES catalog table to include a flag whether the collection is capped (and SIZE and MAX if you can retrieve those values).
Emil, please implement the following SQL changes. When you are done, re-assign this issue back to me and I'll then implement the ADS changes.
CREATE COLLECTION collection_name [ CAPPED { true | false } ] [ SIZE sizeInBytes ] [ MAX_CAP numOfDocuments ]
- Default for CAPPED is false.
- If CAPPED is true, SIZE is the maximum size in bytes for the capped collection.
- If CAPPED is false, SIZE is optional and it specifies the size to preallocate space for the collection.
- MAX_CAP is optional. If CAPPED is true, it specifies a maximum "cap," in number of documents.
ALTER COLLECTION collection_name CAPPED SIZE sizeInBytes
- This command converts a non-capped collection to a capped collection.
Also, update the SHOW COLLECTIONS command and the TABLES catalog table to include a flag whether the collection is capped (and SIZE and MAX if you can retrieve those values).
Implemented support for capped collections , as well as collections with pre-allocated space (i.e. when only the SIZE clause is present).
Renamed [ MAX numOfDocuments ]
to [ MAX_CAP numOfDocuments ]
to avoid grammar parsing collisions when MAX()
is used as aggregate function.
Implemented support for capped collections , as well as collections with pre-allocated space (i.e. when only the SIZE clause is present).
Renamed [ MAX numOfDocuments ]
to [ MAX_CAP numOfDocuments ]
to avoid grammar parsing collisions when MAX()
is used as aggregate function.
In general I don't see SQL keywords havine "_" or "-" in them. If we rename MAX, it should probably be "MAXCAP" instead of "MAX_CAP".
In general I don't see SQL keywords havine "_" or "-" in them. If we rename MAX, it should probably be "MAXCAP" instead of "MAX_CAP".
Added storage options to Collection Detail View and Create/Alter/View Collection Dialog.
Added storage options to Collection Detail View and Create/Alter/View Collection Dialog.
I saw this
"Also, update the SHOW COLLECTIONS command and the TABLES catalog table to include a flag whether the collection is capped (and SIZE and MAX if you can retrieve those values)."
I'm not sure how to document this in the SHOW Commands page. What would this flag look like?
I saw this
"Also, update the SHOW COLLECTIONS command and the TABLES catalog table to include a flag whether the collection is capped (and SIZE and MAX if you can retrieve those values)."
I'm not sure how to document this in the SHOW Commands page. What would this flag look like?
should SHOW Collections be edited to this?
SHOW COLLECTIONS [IN <database_name>] [FOR COLLECTION <collection_name>] [NAMES_ONLY] [SIZE sizeInBytes] [MAX_CAP numofDocuments]
should SHOW Collections be edited to this?
SHOW COLLECTIONS [IN <database_name>] [FOR COLLECTION <collection_name>] [NAMES_ONLY] [SIZE sizeInBytes] [MAX_CAP numofDocuments]
No. The SIZE and MAX_CAP parameters are for the CREATE COLLECTION command, not the SHOW COLLECTIONS command.
No. The SIZE and MAX_CAP parameters are for the CREATE COLLECTION command, not the SHOW COLLECTIONS command.
Verified on ADS 14-beta-64 that for a collection, capped, size and max_cap (number of docs) options are supported (via 'CREATE COLLECTION..' command, create collection option in Collections node). However, the syntax has evolved over the original specified. Also checked that convert to capped is supported via 'ALTER COLLECTION..' command as well as 'alter collection' option on Collections nodes.
Verified on ADS 14-beta-64 that for a collection, capped, size and max_cap (number of docs) options are supported (via 'CREATE COLLECTION..' command, create collection option in Collections node). However, the syntax has evolved over the original specified. Also checked that convert to capped is supported via 'ALTER COLLECTION..' command as well as 'alter collection' option on Collections nodes.
Issue #8735 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
Fixed Build ADS 14.0-dev-48 |
No time estimate |
1 issue link |
relates to #13867
Issue #13867Alter Collection command shows MissingTokenException |
Looks like you might be able to change the storage options : capped collections
You can convert a non-capped collection to a capped collection with the convertToCapped command: