title: How can I set Boolean property to true or false in MongoDB with nodejs
body: <p>I am new to backend development. I am using nodejs with express and mongoose I have successfully updated mongodb with data from a form that mainly contains text so <code>&lt;input type=&quot;text value=&quot;abcdefg&quot;&gt;</code> seems to work fine.</p>
  <p>I have a property field <code>isActive</code> which I'd like to be boolean and have a value of <code>true</code> or <code>false</code></p>
  <p>I tried to do this</p>
  <p><code>&lt;input type=&quot;text&quot; value=&quot;true&quot;&gt;</code></p>
  <p>And I think this is wrong based on some googling (<a href="https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes" rel="nofollow noreferrer">https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes</a>) which mentioned that <em>&quot;The values &quot;true&quot; and &quot;false&quot; are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.&quot;</em>.. so I tried the checkbox method</p>
  <p><code>&lt;input type=&quot;checkbox&quot; checked&gt;</code></p>
  <p>but here I get value = 'on' and it still gives me some error in the console</p>
  <pre><code>messageFormat: undefined,
  stringValue: '&quot;on&quot;',
  kind: 'Boolean',
  value: 'on',
  path: 'isActive',
  reason: CastError: Cast to boolean failed for value &quot;on&quot; (type string) at path &quot;undefined&quot;
  </code></pre>
  <p>Could someone please advise me on how does one define an input field to get a <code>true</code> or <code>false</code> value in Mongodb?</p>