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

Function PreprocessInsertionDoc

pg_documentdb/src/commands/insert.c:1483–1515  ·  view source on GitHub ↗

* Given a bson_value for an insert that was in the insert.documents or bson sequence * ensures it's of a proper form, validates the document, and extracts required * fields from it (shard_key, object_id) and creates a pgbson for insertion. */

Source from the content-addressed store, hash-verified

1481 * fields from it (shard_key, object_id) and creates a pgbson for insertion.
1482 */
1483static pgbson *
1484PreprocessInsertionDoc(const bson_value_t *docValue, MongoCollection *collection,
1485 int64 *shardKeyHash, pgbson **objectId, ExprEvalState *evalState)
1486{
1487 if (evalState != NULL)
1488 {
1489 ValidateSchemaOnDocumentInsert(
1490 evalState, docValue, FAILED_VALIDATION_ERROR_MSG);
1491 }
1492
1493 /* make sure the document has an _id and it is in the right place */
1494 pgbson *insertDoc = RewriteDocumentValueAddObjectId(docValue);
1495
1496 PgbsonValidateInputBson(insertDoc, BSON_VALIDATE_NONE);
1497
1498 /*
1499 * It's possible that the document does not specify the full shard key.
1500 * In that case we will only hash the parts that are specified. That
1501 * is not problematic in terms of querying, because it means this
1502 * object can only be found by queries that do not specify a full
1503 * shard key filter and those queries scan all the shards.
1504 */
1505 *shardKeyHash = ComputeShardKeyHashForDocument(collection->shardKey,
1506 collection->collectionId,
1507 insertDoc);
1508
1509 if (objectId != NULL)
1510 {
1511 *objectId = PgbsonGetDocumentId(insertDoc);
1512 }
1513
1514 return insertDoc;
1515}
1516
1517
1518/*

Callers 2

ProcessInsertionFunction · 0.85

Tested by

no test coverage detected