{"id":10678,"date":"2023-10-26T23:49:54","date_gmt":"2023-10-26T23:49:54","guid":{"rendered":"https:\/\/zappysys.com\/blog\/?p=10678"},"modified":"2024-06-13T05:34:16","modified_gmt":"2024-06-13T05:34:16","slug":"mongodb-query-tricks-getting-information-need","status":"publish","type":"post","link":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/","title":{"rendered":"MongoDB Query Tricks for Getting the Information You Need"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p><a href=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2115 alignleft\" src=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png\" alt=\"\" width=\"100\" height=\"100\" \/><\/a>In this article, we will explore some MongoDB query tricks that can help you retrieve the information you require. Be sure to check out our articles on MongoDB source and MongoDB execute SQL task here.<\/p>\n<div class=\"content_block\" id=\"custom_post_widget-2523\"><h2><span id=\"Prerequisites\">Prerequisites<\/span><\/h2>\r\nBefore we perform the steps listed in this article, you will need to make sure the following prerequisites are met:\r\n<ol style=\"margin-left: 1.5em;\">\r\n \t<li><abbr title=\"SQL Server Integration Services\">SSIS<\/abbr> designer installed.\u00a0Sometimes it is referred to as <abbr title=\"Business Intelligence Development Studio\">BIDS<\/abbr> or <abbr title=\"SQL Server Data Tools\">SSDT<\/abbr> (<a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/ssdt\/download-sql-server-data-tools-ssdt\" target=\"_blank\" rel=\"noopener\">download it from the Microsoft site<\/a>).<\/li>\r\n \t<li>Basic knowledge of SSIS package\u00a0development using\u00a0<em>Microsoft SQL Server Integration Services<\/em>.<\/li>\r\n \t<li>Make sure\u00a0<span style=\"text-decoration: underline;\"><a href=\"https:\/\/zappysys.com\/products\/ssis-powerpack\/\" target=\"_blank\" rel=\"noopener\">ZappySys SSIS PowerPack<\/a><\/span>\u00a0is installed (<a href=\"https:\/\/zappysys.com\/products\/ssis-powerpack\/download\/\" target=\"_blank\" rel=\"noopener\">download it<\/a>, if you haven't already).<\/li>\r\n \t<li>(<em>Optional step<\/em>)<em>.<\/em>\u00a0<a href=\"https:\/\/zappysys.zendesk.com\/hc\/en-us\/articles\/360035974593\" target=\"_blank\" rel=\"noopener\">Read this article<\/a>, if you are planning to deploy packages to a server and schedule their execution later.<\/li>\r\n<\/ol><\/div>\n<h2>Examples<\/h2>\n<p><strong>Filtering by Date:\u00a0<\/strong>First, let&#8217;s look at filtering data by date. Ensure that your database has the date column in the same format.\u00a0You can filter by date using either of these formats:<\/p>\n<p><code>Select date from dataTable where date &gt; '2019-08-17 10:42:20'<\/code><\/p>\n<p>&#8220;Or&#8221;<\/p>\n<p><code>select date from dataTable where date &gt; '2019\/08\/17 10:42:20'<\/code><\/p>\n<p><strong>Getting the Highest Date:\u00a0<\/strong>If you need to retrieve the highest date in a column, you can use the &#8216;Order by&#8217; command along with &#8216;top 1&#8217;. Use DESC for the highst result and ASC for the lowest result.<\/p>\n<p><code>Select top 1 date from dataArray order by date DESC<\/code><\/p>\n<div id=\"attachment_10682\" style=\"width: 498px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-highst-date.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-10682\" class=\"size-full wp-image-10682\" src=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-highst-date.png\" alt=\"MongoDb SQL tricks Highest Date Example\" width=\"488\" height=\"306\" srcset=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-highst-date.png 488w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-highst-date-300x188.png 300w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-highst-date-436x272.png 436w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><p id=\"caption-attachment-10682\" class=\"wp-caption-text\">Highest Date Example<\/p><\/div>\n<p><strong>Sorting Orders:\u00a0<\/strong>The following SQL statement selects all orders from the &#8216;OrdersList&#8217; table. It sorts the results in ascending order by the &#8216;AddressInfo.City&#8217; and in descending order by the &#8216;stars&#8217; column<\/p>\n<p><code>SELECT * FROM OrdersList ORDER BY AddressInfo.City ASC, stars DESC<\/code><\/p>\n<div id=\"attachment_10683\" style=\"width: 471px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-order-by.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-10683\" class=\"size-full wp-image-10683\" src=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-order-by.png\" alt=\"MongoDb SQL tricks order by\" width=\"461\" height=\"453\" srcset=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-order-by.png 461w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-order-by-300x295.png 300w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/a><p id=\"caption-attachment-10683\" class=\"wp-caption-text\">Sorting Orders Example<\/p><\/div>\n<p><strong>Matching Elements in an Array:\u00a0<\/strong>In the next example, we are attempting to match elements inside an array<\/p>\n<p><code>Select * from OrdersList where Tags in ('ca', 'aa')<\/code><\/p>\n<div id=\"attachment_10680\" style=\"width: 487px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-in.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-10680\" class=\"size-full wp-image-10680\" src=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-in.png\" alt=\"MongoDb SQL tricks tags in\" width=\"477\" height=\"392\" srcset=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-in.png 477w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-in-300x247.png 300w\" sizes=\"(max-width: 477px) 100vw, 477px\" \/><\/a><p id=\"caption-attachment-10680\" class=\"wp-caption-text\">Matching Elements Example<\/p><\/div>\n<p><strong>Excluding Elements from an Array:\u00a0<\/strong>You can also exclude elements that are not in the array<\/p>\n<p><code>Select * from OrdersList where Tags NOT in ('ca', 'aa')<\/code><\/p>\n<div id=\"attachment_10681\" style=\"width: 518px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-not-in.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-10681\" class=\"size-full wp-image-10681\" src=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-not-in.png\" alt=\"MongoDb SQL tricks tags not in\" width=\"508\" height=\"385\" srcset=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-not-in.png 508w, https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2023\/10\/MongoDb-SQL-tricks-tags-not-in-300x227.png 300w\" sizes=\"(max-width: 508px) 100vw, 508px\" \/><\/a><p id=\"caption-attachment-10681\" class=\"wp-caption-text\">Excluding Elements Example<\/p><\/div>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>These are some examples that you can utilize with our SQL tool. If you want to explore more complex examples, you can refer to <a href=\"https:\/\/www.w3schools.com\/sql\/\">this article.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this article, we will explore some MongoDB query tricks that can help you retrieve the information you require. Be sure to check out our articles on MongoDB source and MongoDB execute SQL task here. Examples Filtering by Date:\u00a0First, let&#8217;s look at filtering data by date. Ensure that your database has the date column [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":2115,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>MongoDB Query Tricks for Getting the Information You Need | ZappySys Blog<\/title>\r\n<meta name=\"description\" content=\"MongoDB Query Tricks for Getting the Information You Need - ZappySys Blog\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"MongoDB Query Tricks for Getting the Information You Need | ZappySys Blog\" \/>\r\n<meta property=\"og:description\" content=\"MongoDB Query Tricks for Getting the Information You Need - ZappySys Blog\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/\" \/>\r\n<meta property=\"og:site_name\" content=\"ZappySys Blog\" \/>\r\n<meta property=\"article:published_time\" content=\"2023-10-26T23:49:54+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2024-06-13T05:34:16+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png\" \/>\r\n\t<meta property=\"og:image:width\" content=\"88\" \/>\r\n\t<meta property=\"og:image:height\" content=\"88\" \/>\r\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\r\n<meta name=\"author\" content=\"ZappySys Team\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ZappySys Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/\",\"url\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/\",\"name\":\"MongoDB Query Tricks for Getting the Information You Need | ZappySys Blog\",\"isPartOf\":{\"@id\":\"https:\/\/zappysys.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png\",\"datePublished\":\"2023-10-26T23:49:54+00:00\",\"dateModified\":\"2024-06-13T05:34:16+00:00\",\"author\":{\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/91b041e2dcf7ece5f068893c1a68ac6e\"},\"description\":\"MongoDB Query Tricks for Getting the Information You Need - ZappySys Blog\",\"breadcrumb\":{\"@id\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#primaryimage\",\"url\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png\",\"contentUrl\":\"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png\",\"width\":88,\"height\":88},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/zappysys.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MongoDB Query Tricks for Getting the Information You Need\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/zappysys.com\/blog\/#website\",\"url\":\"https:\/\/zappysys.com\/blog\/\",\"name\":\"ZappySys Blog\",\"description\":\"SSIS \/ ODBC Drivers \/ API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/zappysys.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/91b041e2dcf7ece5f068893c1a68ac6e\",\"name\":\"ZappySys Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zappysys.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/746bec9c9d27f1b90bb181aa516ee234?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/746bec9c9d27f1b90bb181aa516ee234?s=96&d=mm&r=g\",\"caption\":\"ZappySys Team\"},\"sameAs\":[\"https:\/\/zappysys.com\"],\"url\":\"https:\/\/zappysys.com\/blog\/author\/dcalbimonte\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MongoDB Query Tricks for Getting the Information You Need | ZappySys Blog","description":"MongoDB Query Tricks for Getting the Information You Need - ZappySys Blog","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:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/","og_locale":"en_US","og_type":"article","og_title":"MongoDB Query Tricks for Getting the Information You Need | ZappySys Blog","og_description":"MongoDB Query Tricks for Getting the Information You Need - ZappySys Blog","og_url":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/","og_site_name":"ZappySys Blog","article_published_time":"2023-10-26T23:49:54+00:00","article_modified_time":"2024-06-13T05:34:16+00:00","og_image":[{"width":88,"height":88,"url":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png","type":"image\/png"}],"author":"ZappySys Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ZappySys Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/","url":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/","name":"MongoDB Query Tricks for Getting the Information You Need | ZappySys Blog","isPartOf":{"@id":"https:\/\/zappysys.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#primaryimage"},"image":{"@id":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#primaryimage"},"thumbnailUrl":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png","datePublished":"2023-10-26T23:49:54+00:00","dateModified":"2024-06-13T05:34:16+00:00","author":{"@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/91b041e2dcf7ece5f068893c1a68ac6e"},"description":"MongoDB Query Tricks for Getting the Information You Need - ZappySys Blog","breadcrumb":{"@id":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#primaryimage","url":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png","contentUrl":"https:\/\/zappysys.com\/blog\/wp-content\/uploads\/2017\/08\/mongodb-logo.png","width":88,"height":88},{"@type":"BreadcrumbList","@id":"https:\/\/zappysys.com\/blog\/mongodb-query-tricks-getting-information-need\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zappysys.com\/blog\/"},{"@type":"ListItem","position":2,"name":"MongoDB Query Tricks for Getting the Information You Need"}]},{"@type":"WebSite","@id":"https:\/\/zappysys.com\/blog\/#website","url":"https:\/\/zappysys.com\/blog\/","name":"ZappySys Blog","description":"SSIS \/ ODBC Drivers \/ API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zappysys.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/91b041e2dcf7ece5f068893c1a68ac6e","name":"ZappySys Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zappysys.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/746bec9c9d27f1b90bb181aa516ee234?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/746bec9c9d27f1b90bb181aa516ee234?s=96&d=mm&r=g","caption":"ZappySys Team"},"sameAs":["https:\/\/zappysys.com"],"url":"https:\/\/zappysys.com\/blog\/author\/dcalbimonte\/"}]}},"_links":{"self":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/10678"}],"collection":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/comments?post=10678"}],"version-history":[{"count":5,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/10678\/revisions"}],"predecessor-version":[{"id":11100,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/posts\/10678\/revisions\/11100"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/media\/2115"}],"wp:attachment":[{"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/media?parent=10678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/categories?post=10678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zappysys.com\/blog\/wp-json\/wp\/v2\/tags?post=10678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}