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

Function ParseCompactCommandSpec

pg_documentdb/src/commands/compact.c:266–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264
265
266static void
267ParseCompactCommandSpec(pgbson *compactSpec, CompactArgs *args)
268{
269 if (compactSpec == NULL)
270 {
271 return;
272 }
273
274 bson_iter_t specIter;
275 PgbsonInitIterator(compactSpec, &specIter);
276 while (bson_iter_next(&specIter))
277 {
278 pgbsonelement element;
279 BsonIterToPgbsonElement(&specIter, &element);
280
281 if (strcmp(element.path, "compact") == 0)
282 {
283 EnsureTopLevelFieldType("compact", &specIter, BSON_TYPE_UTF8);
284 args->collectionName = pstrdup(element.bsonValue.value.v_utf8.str);
285 }
286 else if (strcmp(element.path, "$db") == 0)
287 {
288 EnsureTopLevelFieldType("$db", &specIter, BSON_TYPE_UTF8);
289 args->databaseName = pstrdup(element.bsonValue.value.v_utf8.str);
290 }
291 else if (strcmp(element.path, "force") == 0)
292 {
293 EnsureTopLevelFieldType("force", &specIter, BSON_TYPE_BOOL);
294 args->force = element.bsonValue.value.v_bool;
295 if (!args->force)
296 {
297 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_COMMANDNOTSUPPORTED),
298 errmsg(
299 "command compact option force:false is not supported")));
300 }
301 }
302 else if (strcmp(element.path, "dryRun") == 0)
303 {
304 EnsureTopLevelFieldType("dryRun", &specIter, BSON_TYPE_BOOL);
305 args->dryRun = element.bsonValue.value.v_bool;
306 }
307 else if (strcmp(element.path, "freeSpaceTargetMB") == 0)
308 {
309 EnsureTopLevelFieldIsNumberLike("freeSpaceTargetMB", &element.bsonValue);
310 args->freeSpaceTargetMB = BsonValueAsDouble(&element.bsonValue);
311 }
312 else if (!IsCommonSpecIgnoredField(element.path))
313 {
314 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_UNKNOWNBSONFIELD),
315 errmsg(
316 "The BSON field compact.%s is not recognized as a known field",
317 element.path),
318 errdetail_log(
319 "The BSON field compact.%s is not recognized as a known field",
320 element.path)));
321 }
322 }
323}

Callers 1

command_compactFunction · 0.85

Calls 6

PgbsonInitIteratorFunction · 0.85
BsonIterToPgbsonElementFunction · 0.85
EnsureTopLevelFieldTypeFunction · 0.85
BsonValueAsDoubleFunction · 0.85
IsCommonSpecIgnoredFieldFunction · 0.85

Tested by

no test coverage detected