{"id":2388,"date":"2023-07-22T12:00:18","date_gmt":"2023-07-22T12:00:18","guid":{"rendered":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/"},"modified":"2023-07-22T12:00:18","modified_gmt":"2023-07-22T12:00:18","slug":"query-simile-a-mongodb","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/","title":{"rendered":"Mongodb: come eseguire query con l&#39;espressione regolare &quot;mi piace&quot;."},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Puoi utilizzare i seguenti metodi per interrogare MongoDB con un&#8217;espressione regolare &#8220;mi piace&#8221;:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: trova documenti contenenti una stringa<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.collection.find({ <span style=\"color: #ff0000;\">name<\/span> : { <span style=\"color: #ff0000;\">$regex<\/span> : <span style=\"color: #3366ff;\">\/string\/i<\/span> }})\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che la <span style=\"padding: 1px; border: 1px solid black;\">i<\/span> indica una corrispondenza senza distinzione tra maiuscole e minuscole.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: trova i documenti che iniziano con una stringa<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.collection.find({ <span style=\"color: #ff0000;\">name<\/span> : { <span style=\"color: #ff0000;\">$regex<\/span> : <span style=\"color: #3366ff;\">\/^string\/i<\/span> }}) \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 3: trova i documenti che terminano con una stringa<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.collection.find({ <span style=\"color: #ff0000;\">name<\/span> : { <span style=\"color: #ff0000;\">$regex<\/span> : <span style=\"color: #3366ff;\">\/string$\/i<\/span> }}) \n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo con un <span style=\"padding: 1px; border: 1px solid black;\">team<\/span> di raccolta con i seguenti documenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.insertOne({team: \" <span style=\"color: #008000;\">Mavs<\/span> \", position: \" <span style=\"color: #008000;\">Guard<\/span> \", points: <span style=\"color: #ff0000;\">31<\/span> })<\/strong>\n<strong>db.teams.insertOne({team: \" <span style=\"color: #008000;\">Spurs<\/span> \", position: \" <span style=\"color: #008000;\">Guard<\/span> \", points: <span style=\"color: #ff0000;\">22<\/span> })<\/strong>\n<strong>db.teams.insertOne({team: \" <span style=\"color: #008000;\">Rockets<\/span> \", position: \" <span style=\"color: #008000;\">Center<\/span> \", points: <span style=\"color: #ff0000;\">19<\/span> })<\/strong>\n<strong>db.teams.insertOne({team: \" <span style=\"color: #008000;\">Warriors<\/span> \", position: \" <span style=\"color: #008000;\">Forward<\/span> \", points: <span style=\"color: #ff0000;\">26<\/span> })<\/strong>\n<strong>db.teams.insertOne({team: \" <span style=\"color: #008000;\">Cavs<\/span> \", position: \" <span style=\"color: #008000;\">Guard<\/span> \", points: <span style=\"color: #ff0000;\">33<\/span> })<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: ricerca di documenti contenenti una stringa<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per cercare tutti i documenti che contengono la stringa &#8220;avs&#8221; nel campo team:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.find({ <span style=\"color: #ff0000;\">team<\/span> : { <span style=\"color: #ff0000;\">$regex<\/span> : <span style=\"color: #3366ff;\">\/avs\/i<\/span> }})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa query restituisce i due documenti seguenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>{ _id: ObjectId(\"618050098ffcfe76d07b1da5\"),\n  team: 'Mavs',\n  position: 'Guard',\n  points: 31 }\n\n{ _id: ObjectId(\"618285361a42e92ac9ccd2c6\"),\n  team: 'Cavs',\n  position: 'Guard',\n  points: 33 }<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: trovare documenti che iniziano con una stringa<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per cercare tutti i documenti che iniziano con la stringa &#8220;gua&#8221; nel campo posizione:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.find({ <span style=\"color: #ff0000;\">position<\/span> : { <span style=\"color: #ff0000;\">$regex<\/span> : <span style=\"color: #3366ff;\">\/^gua\/i<\/span> }})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa query restituisce i tre documenti seguenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>{ _id: ObjectId(\"618050098ffcfe76d07b1da5\"),\n  team: 'Mavs',\n  position: 'Guard',\n  points: 31 }\n\n{ _id: ObjectId(\"6180504e8ffcfe76d07b1da7\"),\n  team: 'Spurs',\n  position: 'Guard',\n  points: 22 }\n\n{ _id: ObjectId(\"618285361a42e92ac9ccd2c6\"),\n  team: 'Cavs',\n  position: 'Guard',\n  points: 33 }<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: trovare documenti che terminano con una stringa<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per trovare tutti i documenti che terminano con la stringa &#8220;ward&#8221; nel campo posizione:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.find({ <span style=\"color: #ff0000;\">position<\/span> : { <span style=\"color: #ff0000;\">$regex<\/span> : <span style=\"color: #3366ff;\">\/ward$\/i<\/span> }})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa query restituisce il seguente documento:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>{ _id: ObjectId(\"618050808ffcfe76d07b1dab\"),\n  team: 'Warriors',\n  position: 'Forward',\n  points: 26 }<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione completa per <strong>$regex<\/strong> <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/operator\/query\/regex\/\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puoi utilizzare i seguenti metodi per interrogare MongoDB con un&#8217;espressione regolare &#8220;mi piace&#8221;: Metodo 1: trova documenti contenenti una stringa db.collection.find({ name : { $regex : \/string\/i }}) Tieni presente che la i indica una corrispondenza senza distinzione tra maiuscole e minuscole. Metodo 2: trova i documenti che iniziano con una stringa db.collection.find({ name : [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MongoDB: Come interrogare con Regex &quot;Like&quot; - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come interrogare MongoDB utilizzando un&#039;espressione regolare come, con diversi esempi.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB: Come interrogare con Regex &quot;Like&quot; - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come interrogare MongoDB utilizzando un&#039;espressione regolare come, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-22T12:00:18+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/\",\"url\":\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/\",\"name\":\"MongoDB: Come interrogare con Regex &quot;Like&quot; - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-22T12:00:18+00:00\",\"dateModified\":\"2023-07-22T12:00:18+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come interrogare MongoDB utilizzando un&#39;espressione regolare come, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mongodb: come eseguire query con l&#39;espressione regolare &quot;mi piace&quot;.\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MongoDB: Come interrogare con Regex &quot;Like&quot; - Statorials","description":"Questo tutorial spiega come interrogare MongoDB utilizzando un&#39;espressione regolare come, con diversi esempi.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/","og_locale":"it_IT","og_type":"article","og_title":"MongoDB: Come interrogare con Regex &quot;Like&quot; - Statorials","og_description":"Questo tutorial spiega come interrogare MongoDB utilizzando un&#39;espressione regolare come, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/","og_site_name":"Statorials","article_published_time":"2023-07-22T12:00:18+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/","url":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/","name":"MongoDB: Come interrogare con Regex &quot;Like&quot; - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-22T12:00:18+00:00","dateModified":"2023-07-22T12:00:18+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come interrogare MongoDB utilizzando un&#39;espressione regolare come, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/query-simile-a-mongodb\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/query-simile-a-mongodb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Mongodb: come eseguire query con l&#39;espressione regolare &quot;mi piace&quot;."}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2388"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=2388"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2388\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}