Currently a document looks like this:
{
"Post": "this is a post",
"_id": ObjectId("630f3c32c1a580642a9ff4a0"),
"iframe": ""https:/www.youtube.com/embed/RzVvThhjAKw"",
"slug": "this-is-a-title",
"title": "This is a title"
}
But I want it like this:
{
"Post": "this is a post",
"_id": ObjectId("630f3c32c1a580642a9ff4a0"),
"iframe": "https:/www.youtube.com/embed/RzVvThhjAKw",
"slug": "this-is-a-title",
"title": "This is a title"
}
How to remove double quotes inside double quotes in iframe string field?
2
Answers
For aggregate query, you can work with
$regexFind
to capture the match group.set
– Setiframe
field.1.1.
$first
– Get the first item of array from the result 1.1.1.1.1.1.
$getField
– Get thecaptures
array field from the result of 1.1.1.1.1.1.1.1.
$regexFind
– Return a regex object result from matching theiframe
value with provided regex expression.Demo @ Mongo Playground
You may use
$ifNull
operator to remain the existingiframe
value if it doesn’t match the regex expression.Demo with
$ifNull
@ Mongo PlaygroundIf you want
update
the document in the collection, here’s one way to do it.Try it on mongoplayground.net.