MCPcopy Create free account
hub / github.com/documentdb/documentdb / command_coll_mod

Function command_coll_mod

pg_documentdb/src/commands/coll_mod.c:172–349  ·  view source on GitHub ↗

* command_coll_mod implements the functionality of collMod Database command * dbcommand/collMod. */

Source from the content-addressed store, hash-verified

170 * dbcommand/collMod.
171 */
172Datum
173command_coll_mod(PG_FUNCTION_ARGS)
174{
175 ThrowIfWriteCommandNotAllowed();
176
177 if (PG_ARGISNULL(2))
178 {
179 ereport(ERROR, (errmsg("collMod spec cannot be NULL")));
180 }
181 pgbson *collModSpec = PG_GETARG_PGBSON(2);
182
183 Datum databaseDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0);
184
185 if (PG_ARGISNULL(1))
186 {
187 ereport(ERROR, (errmsg("collection name cannot be NULL")));
188 }
189
190 ReportFeatureUsage(FEATURE_COMMAND_COLLMOD);
191
192 /*
193 * TODO: Restrict collMod command access based on RBAC when it is available
194 */
195
196 /*
197 * Acquire the appropriate lock on the collection for coll_mod.
198 * An exclusive lock is obtained on the collection's data table.
199 * Currently, only the collection itself is locked, since options that could affect
200 * other collections (such as viewOn, pipelines, or validators) are not yet supported.
201 */
202
203 /* Validate the collMod options received because GW only checks for valid collection name */
204 CollModOptions collModOptions = { 0 };
205 CollModSpecFlags specFlags = ParseSpecSetCollModOptions(collModSpec,
206 &collModOptions,
207 &databaseDatum);
208
209 if (databaseDatum == (Datum) 0)
210 {
211 ereport(ERROR, (errmsg("Database name must not be NULL")));
212 }
213
214 if (collModOptions.collectionName == NULL)
215 {
216 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE), (errmsg(
217 "Collection name of collMod options must be specified"))));
218 }
219
220 if (!PG_ARGISNULL(1))
221 {
222 const char *collectionName = TextDatumGetCString(PG_GETARG_DATUM(1));
223
224 if (strcmp(collectionName, collModOptions.collectionName) != 0)
225 {
226 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
227 errmsg(
228 "Collection name specified in the top level must match that in the spec")));
229 }

Callers

nothing calls this directly

Calls 15

ReportFeatureUsageFunction · 0.85
PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
ModifyViewDefinitionFunction · 0.85
HandleColocationFunction · 0.85
IsClusterVersionAtleastFunction · 0.85

Tested by

no test coverage detected