{"id":2765,"date":"2023-07-20T19:34:45","date_gmt":"2023-07-20T19:34:45","guid":{"rendered":"https:\/\/statorials.org\/it\/mongodb-diverso\/"},"modified":"2023-07-20T19:34:45","modified_gmt":"2023-07-20T19:34:45","slug":"mongodb-diverso","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/mongodb-diverso\/","title":{"rendered":"Mongodb: come utilizzare &quot;non uguale&quot; nelle query"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Puoi utilizzare l&#8217;operatore <strong>$ne<\/strong> (che significa &#8220;non uguale&#8221;) in MongoDB per trovare documenti in cui un campo non \u00e8 uguale a un determinato valore.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo operatore utilizza la seguente sintassi di base:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.myCollection.find({' <span style=\"color: #ff0000;\">team<\/span> ': { <span style=\"color: #3366ff;\">$ne<\/span> : \" <span style=\"color: #ff0000;\">Mavs<\/span> \"}})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio cerca tutti i documenti nella raccolta denominata <span style=\"padding: 1px; border: 1px solid black;\">myCollection<\/span> in cui il campo <b>team<\/b> non \u00e8 uguale a &#8220;Mavs&#8221;.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Puoi anche utilizzare l&#8217;operatore <strong>$nin<\/strong> (che significa &#8220;non in&#8221;) per trovare documenti in cui un campo non corrisponde ad alcun valore in un elenco.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questo operatore utilizza la seguente sintassi di base:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.myCollection.find({' <span style=\"color: #ff0000;\">team<\/span> ': { <span style=\"color: #3366ff;\">$nin<\/span> : [\" <span style=\"color: #ff0000;\">Mavs<\/span> \", \" <span style=\"color: #ff0000;\">Cavs<\/span> \", \" <span style=\"color: #ff0000;\">Spurs<\/span> \"]}})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio cerca tutti i documenti nella raccolta denominata <span style=\"padding: 1px; border: 1px solid black;\">myCollection<\/span> in cui il campo <b>della squadra<\/b> non \u00e8 uguale a &#8220;Mavs&#8221;, &#8220;Cavs&#8221; o &#8220;Spurs&#8221;.<\/span><\/p>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare ciascun metodo nella pratica con un <span style=\"padding: 1px; border: 1px solid black;\">team<\/span> di recupero con i seguenti documenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.insertOne({team: \" <span style=\"color: #ff0000;\">Mavs<\/span> \", points: 30, rebounds: 8})\ndb.teams.insertOne({team: \" <span style=\"color: #ff0000;\">Spurs<\/span> \", points: 35, rebounds: 12})\ndb.teams.insertOne({team: \" <span style=\"color: #ff0000;\">Rockets<\/span> \", points: 20, rebounds: 7})\ndb.teams.insertOne({team: \" <span style=\"color: #ff0000;\">Warriors<\/span> \", points: 25, rebounds: 5})\ndb.teams.insertOne({team: \" <span style=\"color: #ff0000;\">Cavs<\/span> \", points: 23, rebounds: 9})<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: query \u201cDiverso\u201d.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come trovare tutti i documenti nella raccolta <span style=\"padding: 1px; border: 1px solid black;\">team<\/span> in cui il campo &#8220;team&#8221; non \u00e8 uguale a &#8220;Mavs&#8221;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.find({' <span style=\"color: #ff0000;\">team<\/span> ': { <span style=\"color: #3366ff;\">$ne<\/span> : \" <span style=\"color: #ff0000;\">Mavs<\/span> \"}})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa query restituisce i seguenti documenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>{ _id: ObjectId(\"6203ec0e1e95a9885e1e7658\"),\n  team: 'Cavs',\n  points: 23,\n  rebounds: 9 }\n{ _id: ObjectId(\"6203ec0e1e95a9885e1e7656\"),\n  team: 'Rockets',\n  points: 20,\n  rebounds: 7 }\n{ _id: ObjectId(\"6203ec0e1e95a9885e1e7655\"),\n  team: 'Spurs',\n  points: 35,\n  rebounds: 12 }\n{ _id: ObjectId(\"6203ec0e1e95a9885e1e7657\"),\n  team: 'Warriors',\n  points: 25,\n  rebounds: 5 }<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che ogni documento nella raccolta <strong>delle squadre<\/strong> viene restituito dove il campo <strong>della squadra<\/strong> non \u00e8 uguale a &#8220;Mavs&#8221;.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : l&#8217;operatore <strong>$ne<\/strong> fa distinzione tra maiuscole e minuscole.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: query \u201cNon in\u201d.<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come trovare tutti i documenti nella raccolta <span style=\"padding: 1px; border: 1px solid black;\">delle squadre<\/span> in cui il campo <strong>della squadra<\/strong> non \u00e8 uguale a &#8220;Mavs&#8221;, &#8220;Cavs&#8221; o &#8220;Spurs&#8221;:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>db.teams.find({' <span style=\"color: #ff0000;\">team<\/span> ': { <span style=\"color: #3366ff;\">$nin<\/span> : [\" <span style=\"color: #ff0000;\">Mavs<\/span> \", \" <span style=\"color: #ff0000;\">Cavs<\/span> \", \" <span style=\"color: #ff0000;\">Spurs<\/span> \"]}})<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questa query restituisce i seguenti documenti:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>{ _id: ObjectId(\"6203ec0e1e95a9885e1e7656\"),\n  team: 'Rockets',\n  points: 20,\n  rebounds: 7 }\n{ _id: ObjectId(\"6203ec0e1e95a9885e1e7657\"),\n  team: 'Warriors',\n  points: 25,\n  rebounds: 5 }<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che ogni documento nella raccolta delle <strong>squadre<\/strong> viene restituito quando il campo <strong>della squadra<\/strong> non \u00e8 uguale a &#8220;Mavs&#8221;, &#8220;Cavs&#8221; o &#8220;Spurs&#8221;.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota n. 1<\/strong> : puoi trovare la documentazione completa per la funzione <strong>$ne<\/strong> <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/operator\/query\/ne\/\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota n.2<\/strong> : puoi trovare la documentazione completa per la funzione <strong>$nin<\/strong> <a href=\"https:\/\/docs.mongodb.com\/manual\/reference\/operator\/query\/nin\/\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre operazioni comuni in MongoDB:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/mongodb-contiene\/\" target=\"_blank\" rel=\"noopener\">MongoDB: come verificare se il campo contiene una stringa<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/mongodb-non-nullo\/\">MongoDB: come cercare &#8220;not null&#8221; in un campo specifico<\/a><br \/><a href=\"https:\/\/statorials.org\/it\/stringa-di-sostituzione-mongodb\/\" target=\"_blank\" rel=\"noopener\">MongoDB: come sostituire le stringhe<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puoi utilizzare l&#8217;operatore $ne (che significa &#8220;non uguale&#8221;) in MongoDB per trovare documenti in cui un campo non \u00e8 uguale a un determinato valore. Questo operatore utilizza la seguente sintassi di base: db.myCollection.find({&#8216; team &#8216;: { $ne : &#8221; Mavs &#8220;}}) Questo particolare esempio cerca tutti i documenti nella raccolta denominata myCollection in cui il [&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 utilizzare \u201cNot Equal\u201d nelle query \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare &quot;different&quot; nelle query in MongoDB, 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\/mongodb-diverso\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB: come utilizzare \u201cNot Equal\u201d nelle query \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare &quot;different&quot; nelle query in MongoDB, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/mongodb-diverso\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-20T19:34:45+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\/mongodb-diverso\/\",\"url\":\"https:\/\/statorials.org\/it\/mongodb-diverso\/\",\"name\":\"MongoDB: come utilizzare \u201cNot Equal\u201d nelle query \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-20T19:34:45+00:00\",\"dateModified\":\"2023-07-20T19:34:45+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare &quot;different&quot; nelle query in MongoDB, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/mongodb-diverso\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/mongodb-diverso\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/mongodb-diverso\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mongodb: come utilizzare &quot;non uguale&quot; nelle query\"}]},{\"@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 utilizzare \u201cNot Equal\u201d nelle query \u2013 Statorials","description":"Questo tutorial spiega come utilizzare &quot;different&quot; nelle query in MongoDB, 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\/mongodb-diverso\/","og_locale":"it_IT","og_type":"article","og_title":"MongoDB: come utilizzare \u201cNot Equal\u201d nelle query \u2013 Statorials","og_description":"Questo tutorial spiega come utilizzare &quot;different&quot; nelle query in MongoDB, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/mongodb-diverso\/","og_site_name":"Statorials","article_published_time":"2023-07-20T19:34:45+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\/mongodb-diverso\/","url":"https:\/\/statorials.org\/it\/mongodb-diverso\/","name":"MongoDB: come utilizzare \u201cNot Equal\u201d nelle query \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-20T19:34:45+00:00","dateModified":"2023-07-20T19:34:45+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare &quot;different&quot; nelle query in MongoDB, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/mongodb-diverso\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/mongodb-diverso\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/mongodb-diverso\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Mongodb: come utilizzare &quot;non uguale&quot; nelle query"}]},{"@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\/2765"}],"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=2765"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2765\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}