summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/commands/write_commands.cpp57
-rw-r--r--src/mongo/db/timeseries/timeseries_update_delete_util.cpp36
-rw-r--r--src/mongo/db/timeseries/timeseries_update_delete_util.h11
3 files changed, 59 insertions, 45 deletions
diff --git a/src/mongo/db/commands/write_commands.cpp b/src/mongo/db/commands/write_commands.cpp
index d86302032dd..f81e905254b 100644
--- a/src/mongo/db/commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands.cpp
@@ -63,6 +63,7 @@
#include "mongo/db/storage/duplicate_key_error_info.h"
#include "mongo/db/storage/storage_parameters_gen.h"
#include "mongo/db/timeseries/bucket_catalog.h"
+#include "mongo/db/timeseries/timeseries_index_schema_conversion_functions.h"
#include "mongo/db/timeseries/timeseries_update_delete_util.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/views/view_catalog.h"
@@ -129,48 +130,6 @@ bool isMetaFieldFirstElementOfDottedPathField(StringData metaField, StringData f
return field.substr(0, field.find('.')) == metaField;
}
-// TODO: SERVER-58394 Remove this method and combine its logic with
-// timeseries::replaceTimeseriesQueryMetaFieldName().
-/**
- * Recurses through the mutablebson element query and replaces any occurrences of the
- * metaField with "meta" accounting for queries that may be in dot notation. shouldReplaceFieldValue
- * is set for $expr queries when "$" + the metaField should be subsitutited for "$meta".
- */
-void replaceTimeseriesQueryMetaFieldName(mutablebson::Element elem,
- const StringData& metaField,
- bool shouldReplaceFieldValue = false) {
- if (metaField.empty()) {
- return;
- }
- shouldReplaceFieldValue = (elem.getFieldName() != "$literal") &&
- (shouldReplaceFieldValue || (elem.getFieldName() == "$expr"));
- if (isMetaFieldFirstElementOfDottedPathField(metaField, elem.getFieldName())) {
- size_t dotIndex = elem.getFieldName().find('.');
- dotIndex >= elem.getFieldName().size()
- ? invariantStatusOK(elem.rename("meta"))
- : invariantStatusOK(elem.rename(
- "meta" +
- elem.getFieldName().substr(dotIndex, elem.getFieldName().size() - dotIndex)));
- }
- // Substitute element fieldValue with "$meta" if element is a subField of $expr, not a subField
- // of $literal, and the element fieldValue is "$" + the metaField.
- else if (shouldReplaceFieldValue && elem.isType(BSONType::String) &&
- isMetaFieldFirstElementOfDottedPathField("$" + metaField, elem.getValueString())) {
- size_t dotIndex = elem.getValueString().find('.');
- dotIndex >= elem.getValueString().size()
- ? invariantStatusOK(elem.setValueString("$meta"))
- : invariantStatusOK(elem.setValueString(
- "$meta" +
- elem.getValueString().substr(dotIndex, elem.getValueString().size() - dotIndex)));
- }
- if (elem.hasChildren()) {
- for (size_t i = 0; i < elem.countChildren(); ++i) {
- replaceTimeseriesQueryMetaFieldName(
- elem.findNthChild(i), metaField, shouldReplaceFieldValue);
- }
- }
-}
-
// Default for control.version in time-series bucket collection.
const int kTimeseriesControlVersion = 1;
@@ -1541,10 +1500,18 @@ public:
timeseriesDeletes.reserve(request().getDeletes().size());
for (auto& deleteEntry : request().getDeletes()) {
// TODO: SERVER-58394 Call timeseries::translateQuery() here instead.
- mutablebson::Document doc(deleteEntry.getQ());
- replaceTimeseriesQueryMetaFieldName(doc.root(), metaField);
+ mutablebson::Document queryDoc(deleteEntry.getQ());
+ timeseries::replaceTimeseriesQueryMetaFieldName(queryDoc.root(), metaField);
timeseriesDeletes.push_back(deleteEntry);
- timeseriesDeletes.back().setQ(doc.getObject());
+ timeseriesDeletes.back().setQ(queryDoc.getObject());
+
+ // Only translate the hint if it is specified by index spec.
+ if (deleteEntry.getHint().firstElement().fieldNameStringData() != "$hint"_sd ||
+ deleteEntry.getHint().firstElement().type() != BSONType::String) {
+ timeseriesDeletes.back().setHint(
+ uassertStatusOK(timeseries::createBucketsIndexSpecFromTimeseriesIndexSpec(
+ *timeseriesOptions, deleteEntry.getHint())));
+ }
}
write_ops::DeleteCommandRequest timeseriesDeleteReq(
diff --git a/src/mongo/db/timeseries/timeseries_update_delete_util.cpp b/src/mongo/db/timeseries/timeseries_update_delete_util.cpp
index 5eafea0d762..f38a5681e19 100644
--- a/src/mongo/db/timeseries/timeseries_update_delete_util.cpp
+++ b/src/mongo/db/timeseries/timeseries_update_delete_util.cpp
@@ -31,6 +31,7 @@
#include "mongo/db/pipeline/expression_context.h"
#include "mongo/db/pipeline/pipeline.h"
+#include "mongo/db/timeseries/timeseries_constants.h"
namespace mongo::timeseries {
namespace {
@@ -259,4 +260,39 @@ write_ops::UpdateOpEntry translateUpdate(const BSONObj& translatedQuery,
}
MONGO_UNREACHABLE;
}
+
+void replaceTimeseriesQueryMetaFieldName(mutablebson::Element elem,
+ const StringData& metaField,
+ bool shouldReplaceFieldValue) {
+ if (metaField.empty()) {
+ return;
+ }
+ shouldReplaceFieldValue = (elem.getFieldName() != "$literal") &&
+ (shouldReplaceFieldValue || (elem.getFieldName() == "$expr"));
+ if (isMetaFieldFirstElementOfDottedPathField(elem.getFieldName(), metaField)) {
+ size_t dotIndex = elem.getFieldName().find('.');
+ dotIndex >= elem.getFieldName().size()
+ ? invariantStatusOK(elem.rename("meta"))
+ : invariantStatusOK(elem.rename(
+ "meta" +
+ elem.getFieldName().substr(dotIndex, elem.getFieldName().size() - dotIndex)));
+ }
+ // Substitute element fieldValue with "$meta" if element is a subField of $expr, not a subField
+ // of $literal, and the element fieldValue is "$" + the metaField.
+ else if (shouldReplaceFieldValue && elem.isType(BSONType::String) &&
+ isMetaFieldFirstElementOfDottedPathField(elem.getValueString(), "$" + metaField)) {
+ size_t dotIndex = elem.getValueString().find('.');
+ dotIndex >= elem.getValueString().size()
+ ? invariantStatusOK(elem.setValueString("$meta"))
+ : invariantStatusOK(elem.setValueString(
+ "$meta" +
+ elem.getValueString().substr(dotIndex, elem.getValueString().size() - dotIndex)));
+ }
+ if (elem.hasChildren()) {
+ for (size_t i = 0; i < elem.countChildren(); ++i) {
+ replaceTimeseriesQueryMetaFieldName(
+ elem.findNthChild(i), metaField, shouldReplaceFieldValue);
+ }
+ }
+}
} // namespace mongo::timeseries
diff --git a/src/mongo/db/timeseries/timeseries_update_delete_util.h b/src/mongo/db/timeseries/timeseries_update_delete_util.h
index 12cb1887ac3..43a7bf6850f 100644
--- a/src/mongo/db/timeseries/timeseries_update_delete_util.h
+++ b/src/mongo/db/timeseries/timeseries_update_delete_util.h
@@ -66,4 +66,15 @@ write_ops::UpdateOpEntry translateUpdate(const BSONObj& translatedQuery,
const write_ops::UpdateModification& updateMod,
StringData metaField);
+// TODO: SERVER-58394 Remove this method and combine its logic with
+// timeseries::replaceTimeseriesQueryMetaFieldName().
+/**
+ * Recurses through the mutablebson element query and replaces any occurrences of the
+ * metaField with "meta" accounting for queries that may be in dot notation. shouldReplaceFieldValue
+ * is set for $expr queries when "$" + the metaField should be substituted for "$meta".
+ */
+void replaceTimeseriesQueryMetaFieldName(mutablebson::Element elem,
+ const StringData& metaField,
+ bool shouldReplaceFieldValue = false);
+
} // namespace mongo::timeseries