{"id":28229,"date":"2023-09-27T09:56:22","date_gmt":"2023-09-27T07:56:22","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=28229"},"modified":"2023-09-27T09:56:26","modified_gmt":"2023-09-27T07:56:26","slug":"mongodb-identify-a-field-type","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/","title":{"rendered":"MongoDB: Identify a field type"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"h-introduction\">Introduction<\/h2>\n\n\n\n<p>Whereas I wanted to perform a quick demo to show some MongoDB useful command to mass<\/p>\n\n\n\n<p>update some fields (Increment),I had a MongoDB error: \u201cCannot increment with a non-numeric argument\u201d<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png\" alt=\"\" class=\"wp-image-28232\" style=\"width:1175px;height:41px\" width=\"1175\" height=\"41\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png 602w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64-300x10.png 300w\" sizes=\"auto, (max-width: 1175px) 100vw, 1175px\" \/><\/figure>\n\n\n\n<p>I guess the message is explicit:<\/p>\n\n\n\n<p>I can\u2019t update this field as it is not a numeric field<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-identify-the-field-type\">Identify the field type:<\/h2>\n\n\n\n<p>As I have created my document with basic commands without specifying each field type, the fields are set by default (<strong>undefined<\/strong> )<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-know-the-type-of-your-field\">How to know the type of your field?<\/h2>\n\n\n\n<p>For my example I have this list of players, their name, and also their <strong>number<\/strong> of goals.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-66-1024x629.png\" alt=\"\" class=\"wp-image-28236\" style=\"width:942px;height:579px\" width=\"942\" height=\"579\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-66-1024x629.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-66-300x184.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-66-768x471.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-66.png 1336w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/figure>\n\n\n\n<p>When I wanted to increment the &#8220;goals&#8221; field by 10 it displayed the famous issue.<\/p>\n\n\n\n<p>Let&#8217;s check the goals field type:<\/p>\n\n\n\n<p>For that we will use the below command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>typeof <\/strong>db.collection.findOne().<strong>field_name<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>selecao_cracks&gt; typeof db.selecao_cracks.findOne().Lastname<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-68-1024x326.png\" alt=\"\" class=\"wp-image-28241\" style=\"width:946px;height:301px\" width=\"946\" height=\"301\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-68-1024x326.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-68-300x96.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-68-768x245.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-68.png 1344w\" sizes=\"auto, (max-width: 946px) 100vw, 946px\" \/><\/figure>\n\n\n\n<p>Here we see that <strong>Lastname <\/strong>field is undefined<\/p>\n\n\n\n<p>If we take a look we see that Nickname field is a string type (I made some tests before) <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"159\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-69-1024x159.png\" alt=\"\" class=\"wp-image-28245\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-69-1024x159.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-69-300x47.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-69-768x119.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-69.png 1096w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-type-operator\">The $TYPE operator:<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/query\/type\/#mongodb-query-op.-type\"><code>$type<\/code><\/a> operator accepts string aliases for the BSON types in addition to the numbers corresponding to the BSON types<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"903\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-67.png\" alt=\"\" class=\"wp-image-28240\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-67.png 748w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-67-249x300.png 249w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-update-the-type-of-the-field\">Update the type of the field<\/h2>\n\n\n\n<p>Use the <strong>$set<\/strong> operator and the <strong>$toInt<\/strong> operator to update the field ( In fact in that case the <strong>$set<\/strong> operator will replace the field and its type, later we will see that we can use another operator name <strong>$convert <\/strong>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>selecao_cracks&gt; db.selecao_cracks.updateMany( {}, &#091;{ <strong>$set<\/strong> : { \"goals\":{<strong>$toInt<\/strong>:\"$goals\"}}} ]);<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-70-1024x277.png\" alt=\"\" class=\"wp-image-28249\" style=\"width:993px;height:269px\" width=\"993\" height=\"269\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-70-1024x277.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-70-300x81.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-70-768x208.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-70-1536x415.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-70.png 1621w\" sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check if the field is updated<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-71-1024x204.png\" alt=\"\" class=\"wp-image-28251\" style=\"width:990px;height:197px\" width=\"990\" height=\"197\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-71-1024x204.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-71-300x60.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-71-768x153.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-71.png 1328w\" sizes=\"auto, (max-width: 990px) 100vw, 990px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-increment-the-field-to-check-if-the-command-is-now-valid\">Increment the field to check if the command is now valid<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>selecao_cracks&gt; db.selecao_cracks.updateMany( {}, { $inc : { goals : 10 } });<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-72-1024x198.png\" alt=\"\" class=\"wp-image-28253\" style=\"width:993px;height:192px\" width=\"993\" height=\"192\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-72-1024x198.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-72-300x58.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-72-768x148.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-72-1536x297.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-72.png 1642w\" sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Now let&#8217;s check if update is done <\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-73-1024x601.png\" alt=\"\" class=\"wp-image-28255\" style=\"width:988px;height:580px\" width=\"988\" height=\"580\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-73-1024x601.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-73-300x176.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-73-768x450.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-73.png 1398w\" sizes=\"auto, (max-width: 988px) 100vw, 988px\" \/><\/figure>\n\n\n\n<p>That&#8217;s it update worked and we don&#8217;t have the error related to the data type \ud83d\ude42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-other-operators\">The other operators<\/h2>\n\n\n\n<p>We have also other operator to change our field type such as:<\/p>\n\n\n\n<p><strong>$toString<\/strong><\/p>\n\n\n\n<p>As it&#8217;s name says it is to change the field to a string type<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-74-1024x276.png\" alt=\"\" class=\"wp-image-28285\" style=\"width:989px;height:267px\" width=\"989\" height=\"267\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-74-1024x276.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-74-300x81.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-74-768x207.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-74-1536x414.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-74.png 1867w\" sizes=\"auto, (max-width: 989px) 100vw, 989px\" \/><\/figure>\n\n\n\n<p><strong>$toDate<\/strong><\/p>\n\n\n\n<p>this operator allows you to modify the field as a <strong>date <\/strong>type<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"699\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-75-1024x699.png\" alt=\"\" class=\"wp-image-28305\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-75-1024x699.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-75-300x205.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-75-768x524.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-75.png 1216w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We check the data type:<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-77-1024x242.png\" alt=\"\" class=\"wp-image-28308\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-77-1024x242.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-77-300x71.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-77-768x182.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-77-1536x363.png 1536w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-77.png 1703w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Update the field<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ballon_d_or_winner&gt; db.ballon_d_or_forgotten.updateOne( {\"name\":\"Zico\"}, &#091;{ $set : { \"date\":{$toDate:\"$date\"}}} ]);\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The output shows that it worked<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"231\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-79-1024x231.png\" alt=\"\" class=\"wp-image-28315\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-79-1024x231.png 1024w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-79-300x68.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-79-768x173.png 768w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-79.png 1414w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We see that the format is note an <strong>ISODate <\/strong>format<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"864\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-78.png\" alt=\"\" class=\"wp-image-28314\" srcset=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-78.png 880w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-78-300x295.png 300w, https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-78-768x754.png 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p><strong>$Convert<\/strong><\/p>\n\n\n\n<p>For converting the data type of a field in MongoDB.<\/p>\n\n\n\n<p>More information related to <strong>$Convert <\/strong>on the <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/convert\/\">MongoDB site<\/a> <\/p>\n\n\n\n<p>This operator is very effective and can convert a field to any data type, or it can convert a field to null if the conversion is not possible.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/convert\/#mongodb-expression-exp.-convert\"><code>$convert<\/code><\/a> has the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br>$convert:<br>{<br>input: ,<br>to: ,<br>onError: , \/\/ Optional.<br>onNull: \/\/ Optional.<br>}<br>}<\/code><\/pre>\n\n\n\n<p>In addition to <a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/convert\/#mongodb-expression-exp.-convert\"><code>$convert<\/code><\/a>, MongoDB provides the following aggregation operators as shorthand when the default &#8220;onError&#8221; and &#8220;onNull&#8221; behavior is acceptable:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toBool\/#mongodb-expression-exp.-toBool\"><code>$toBool<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toDate\/#mongodb-expression-exp.-toDate\"><code>$toDate<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toDecimal\/#mongodb-expression-exp.-toDecimal\"><code>$toDecimal<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toDouble\/#mongodb-expression-exp.-toDouble\"><code>$toDouble<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toInt\/#mongodb-expression-exp.-toInt\"><code>$toInt<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toLong\/#mongodb-expression-exp.-toLong\"><code>$toLong<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toObjectId\/#mongodb-expression-exp.-toObjectId\"><code>$toObjectId<\/code><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mongodb.com\/docs\/manual\/reference\/operator\/aggregation\/toString\/#mongodb-expression-exp.-toString\"><code>$toString<\/code><\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion <\/h2>\n\n\n\n<p>Now you know how to update a field with the correct type especially when you need to performs tasks using integer values.<\/p>\n\n\n\n<p>I hope it helped, next time we will go deeper with these kind of operator especially combined with aggregations as it is a huge topic with many use cases.<\/p>\n\n\n\n<p>Don&#8217;t hesitate to check <a href=\"https:\/\/www.dbi-services.com\/blog\/author\/nabilsaoual\/page\/5\/\">my other blogs<\/a> and share with dbi bloggers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Whereas I wanted to perform a quick demo to show some MongoDB useful command to mass update some fields (Increment),I had a MongoDB error: \u201cCannot increment with a non-numeric argument\u201d I guess the message is explicit: I can\u2019t update this field as it is not a numeric field Identify the field type: As I [&hellip;]<\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1739],"tags":[],"type_dbi":[],"class_list":["post-28229","post","type-post","status-publish","format-standard","hentry","category-nosql"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>MongoDB: Identify a field type - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MongoDB: Identify a field type\" \/>\n<meta property=\"og:description\" content=\"Introduction Whereas I wanted to perform a quick demo to show some MongoDB useful command to mass update some fields (Increment),I had a MongoDB error: \u201cCannot increment with a non-numeric argument\u201d I guess the message is explicit: I can\u2019t update this field as it is not a numeric field Identify the field type: As I [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-27T07:56:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-27T07:56:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png\" \/>\n<meta name=\"author\" content=\"Middleware Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Middleware Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\"},\"author\":{\"name\":\"Middleware Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1\"},\"headline\":\"MongoDB: Identify a field type\",\"datePublished\":\"2023-09-27T07:56:22+00:00\",\"dateModified\":\"2023-09-27T07:56:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\"},\"wordCount\":477,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png\",\"articleSection\":[\"NoSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\",\"name\":\"MongoDB: Identify a field type - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png\",\"datePublished\":\"2023-09-27T07:56:22+00:00\",\"dateModified\":\"2023-09-27T07:56:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MongoDB: Identify a field type\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1\",\"name\":\"Middleware Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g\",\"caption\":\"Middleware Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/middleware-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"MongoDB: Identify a field type - dbi 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:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/","og_locale":"en_US","og_type":"article","og_title":"MongoDB: Identify a field type","og_description":"Introduction Whereas I wanted to perform a quick demo to show some MongoDB useful command to mass update some fields (Increment),I had a MongoDB error: \u201cCannot increment with a non-numeric argument\u201d I guess the message is explicit: I can\u2019t update this field as it is not a numeric field Identify the field type: As I [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/","og_site_name":"dbi Blog","article_published_time":"2023-09-27T07:56:22+00:00","article_modified_time":"2023-09-27T07:56:26+00:00","og_image":[{"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png","type":"","width":"","height":""}],"author":"Middleware Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Middleware Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/"},"author":{"name":"Middleware Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1"},"headline":"MongoDB: Identify a field type","datePublished":"2023-09-27T07:56:22+00:00","dateModified":"2023-09-27T07:56:26+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/"},"wordCount":477,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png","articleSection":["NoSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/","url":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/","name":"MongoDB: Identify a field type - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png","datePublished":"2023-09-27T07:56:22+00:00","dateModified":"2023-09-27T07:56:26+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2023\/09\/image-64.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/mongodb-identify-a-field-type\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"MongoDB: Identify a field type"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/8d8563acfc6e604cce6507f45bac0ea1","name":"Middleware Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ddcae7ba0f9d1a0e7ae707f0e689e4a9c95bb48ec49c8e6d9cc86d43f4121cb6?s=96&d=mm&r=g","caption":"Middleware Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/middleware-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/28229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=28229"}],"version-history":[{"count":33,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/28229\/revisions"}],"predecessor-version":[{"id":28333,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/28229\/revisions\/28333"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=28229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=28229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=28229"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=28229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}