Updating MongoDB's binary data subtype

Is there a way to modify just the subtype of the Binary element in MongoDB?
I currently have a Binary element in my database with type 0x00
BinData(0, xxx)
Can this be done using the shell to only update the subType and change it to a different value?

Or is it necessary to create a new property with the old binary part?

new BinData(newVal, xxx)

Answer №1

The only method available is to generate a new BinData by using the previous base64 value and calling the .base64() method.

> var bin = new BinData(3,"ASNFZ4mrze/+3LqYdlQyEA==")
> var newType = 0;
> bin = new BinData(newType, bin.base64());
BinData(0,"ASNFZ4mrze/+3LqYdlQyEA==")

This is because the type property cannot be changed, as indicated by the output of

Object.getOwnPropertyDescriptor()

> Object.getOwnPropertyDescriptor(bin, 'type')
{
        "configurable" : true,
        "enumerable" : false,
        "value" : 0,
        "writable" : false
}

For instance:

> bin.type;
0
> bin.type = 3;
3
> bin.type;
0

Even after attempting to change it to 3, the value of bin.type remains unchanged

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensuring the proper sequence of operations within a jQuery ajax callback function

I am facing an issue with my jQuery ajax function. The callback function includes two actions: 1) Taking the ajax result (which is an html form) and inserting it as the inner html of an html span. 2) Submitting this form How can I make sure that the form ...

Using AngularJS, display content only if the JSON response is [false]

Recently, I started learning AngularJS and am currently working on a project where I need a div to only be visible when the JSON data returns [false]. Sometimes, the JSON does return [false] particularly when there are no results from the query. JavaScrip ...

Guide on initiating the mongodb daemon using Python

How can I execute the MongoDB daemon using Python? Below is my current script: import subprocess subprocess.Popen(['C:\\mongodb\\bin\\mongod', '----dbpath C:\\dropbox\\projects&bsol ...

Tips for updating datatables following an ajax request

I've attempted various methods to refresh my data table following an AJAX Call but have had no success. I have tried using the draw() and ajax.reload() functions, but nothing seems to be working. Do you have any suggestions on how I can successfully r ...

Verifying assigned role and running a specified task

I have a task to verify if a user possesses a specific role, and if they do, to remove it. If the user does not have the role, then display a certain message. let user = message.guild.member(message.mentions.users.first() || message.guild.members.get(args ...

Extracting data from a Wikipedia table using web scraping in JavaScript

I'm attempting to extract information from a specific website. <script> var convertToInt; var allData = []; $.ajax({ url: "http://en.wikipedia.org/wiki/Demographics_of_Europe", type: 'GET', cache: false, success: func ...

Displaying or concealing fields through Javascript depending on the category type of the results item

I am facing an issue with displaying certain fields in each individual property search result based on the property type. For example, if a property is classified as Land, I do not want the bedrooms and bathrooms fields to be visible, but if it is a Villa, ...

Is there a way to maintain formdata between components in Angular?

With only the tools of @Input, @Output, routing, and activatedRoute at my disposal, I set out to create a dynamic application. In this project, there are two crucial components: addbook and showbook. The addbook component features a form with a submit bu ...

Deactivate collapsing of active element in Bootstrap 5 accordion without using jQuery

Check out this example of a Bootstrap 5 Accordion element: <div id="accordion-1" class="accordion" role="tablist"> <div class="accordion-item"> <h2 class="accordion-header" role=& ...

Stop unauthorized access to php files when submitting a contact form

I have implemented a contact form on my HTML page that sends an email via a PHP script upon submission. However, when the form is submitted, the PHP script opens in a new page instead of staying on the current page where the form resides. I have tried usin ...

Dynamically fetching data with Node.js using Ajax requests

Despite my efforts to scour Google and Stack Overflow, I have been unable to find a reliable method for posting data to my Node.js server. I've noticed conflicting information on various methods, likely due to changes over time. One particular code ...

What is the best method to retrieve an object using req.body?

For my new survey, I want users to input their own questions based on the type of survey (Multiple Choice or True/False). However, I am facing a challenge with accessing the QuestionText string in the "MC" object through req.body.Questions. Below is how my ...

tips for decreasing box size diagonally while scrolling down

$(function(){ var navIsBig = true; var $nav = $('#header_nav'); $(document).scroll( function() { var value = $(this).scrollTop(); if ( value > 50 && navIsBig ){ $nav.animate({height:45},"medium"); $('.box ...

Trouble with the width of the message container in CSS styling

I need to display a message at the top-center of my webpage. I have created a simple example for this: http://jsbin.com/eniwax/3/edit The issue I am facing is with the width of the message container. I want the container width to adjust dynamically based ...

Tips for adjusting height responsively with Bootstrap 4

Utilizing bootstrap to create div elements. Check out the fiddle link below: fiddle On my page, I have 4 divs - two on top and two at the bottom. The height of all 4 card divs should remain the same and not change. In the last div, there could be on ...

Steps to create a basic multi-select dropdown menu with Select2

I have decided to integrate the select2 library into my HTML document because it offers a sleek pillbox style select control that fits well with my design. After carefully following the instructions in the Installation and Getting Started sections of the ...

What is the process of including assetlinks.json in an Angular project to enable Android App Links?

Hey everyone, I could really use some assistance! I'm unsure about the specific directory to place the assetlinks.json file and what additional information needs to be included for it to function properly. I do have a SHA256 key and applicationId, so ...

How to add a service to a static function in Angular

After incorporating a logger service into my project, I have encountered an issue with using it in NGXS static selectors. The selectors in NGXS are static methods, which prevent me from accessing the logger service injected via Angular DI. Are there any e ...

Is it possible to change the background color of the scrolling page?

Let's say I have 10 different sections, each with a unique background color assigned to them. As the user scrolls down from section 1 through 10, my goal is to dynamically change the body tag's background color based on which section is currentl ...

Combining arrays of properties in two objects

Below are the JavaScript objects I am working with: Object A: 0300 : ["295", "293", "298"], 0800 : ["293", "298"], 0930 : ["295"], 1130 : ["297", "293", "298"], 1230 : ["295"] Object B: 0300 : ["297"], 0800 : ["297"], 0930 : ["293"], I aim to merge th ...