Storing data with dots in MongoDB

I need help with saving JSON API data to a MongoDB collection. The JSON data I am working with has a structure like this:

compatibility: {
    2.7.1: {
        2.2.6: [
            100,
            1,
            1
        ]
     },
     2.8.3: {
         2.2.6: [
             100,
             2,
             2
         ]
     }
 }

However, I am encountering an error that says: The dotted field '2.7.1' in 'compatibility.2.7.1' is not valid for storage.

Can anyone provide guidance on how to resolve this issue?

Answer №1

In field names, using a period . is not allowed. The period has a special meaning in mongodb, so it's best to avoid using it. For instance, if you were to insert

db.test.insert({
   a: {
      b: 2
   }
});

You would then search for that item using

db.test.find({
   'a.b': 2
});

Now, consider if you were to include a field name with a period and insert

db.test.insert({
   a: {
      b: 2
   },
   'a.b': 3
});

It would be quite unusual to search for 'a.b', right?

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

Run a series of Mocha unit tests based on the outcomes of previous test results

Currently, I am in the process of writing unit tests for a NodeJS application that I am developing. In relation to some unit-testing logic, I have a question. Imagine if the application first creates a "Group" for users, followed by creating individual Us ...

What is the most effective way to reset the v-model in the child component using the parent component?

Could you please assist me? I have been trying for 10 hours straight and it doesn't seem to work. What I am aiming for is that when I click on @click="cleanDataForm" in the Parent Component, the v-model text in the Child component will be emptied. I h ...

When using requirejs and vue.js together, the error message "Vue is not defined" may be encountered

My code snippet looks like this: <script type="text/javascript" src="../../node_modules/requirejs/require.js"></script> <script type="text/javascript" src="../../node_modules/vue/dist/vue.js"></script> <script>console.log(Vue ...

Encountering an issue when trying to submit a post request: "Received an API resolution without a response for /api/comments, which could lead to delayed requests."

Hey, I recently started diving into Next.js and I'm facing an issue with making a POST request to the API. In my project structure, I have a comments folder nested inside the api folder. Within the comments folder, I've written the following cod ...

Can anyone provide guidance on utilizing JSON with jQuery for reading purposes?

{ "Joining_date":[ "From Date should not be empty." ], "End_date":[ "To Date should not be empty." ], "Company_name":[ "Company name is required." ], "Job_title":[ "Designat ...

Utilizing Radio Buttons for Table Selection in a React Application

Currently, I am utilizing React, MUI, and Formik in my project. My task involves implementing a table where only one radio button can be selected per row. How can I achieve this functionality? If you want to take a look at my code, it's available on ...

Is it possible to fetch JSON data in PHP without having to encode it with json_encode()?

I've been trying my luck, but I'm curious if it's possible to retrieve JSON data if it's not encoded server-side with PHP. For instance, if I were to simply output some data like this: echo '{"subscriptions": [{"subscribe":"' ...

Rendering React Js component occurs just once following a state update

My journey with ReactJS is just beginning, and I'm facing an unusual issue which might be due to my unconventional implementation approach. Previously, everything was working smoothly. However, when I tried to introduce new features, things started g ...

Retrieving time zone using offset with javascript

I am looking for a way to schedule time-based events on my server operating in UTC time. For the user interface, I need to input 2 parameters: The local time when the scheduled event should trigger The timezone offset Instead of displaying timezone n ...

Send multiple input groups using Ajax POST requests

I need help setting up a form with 4 groups of checkboxes for refining search results. My goal is to send an array for each checkbox group that contains the IDs of the currently selected checkboxes. $.ajax({ url: "/stay_in_belfast/accommodation", t ...

The React Component is limited to updating once

Exploring the React Native code below: import React from 'react'; import {Text, View, StyleSheet, Button} from 'react-native'; export default class Target extends React.Component { constructor(props){ super(props); ...

Selected value is not displayed in the textbox when using autocomplete feature

---Ajax---- An issue has arisen with the autocomplete feature. While typing "wi" (for example, wipro), the drop-down list appears as expected. However, if only "wi" is selected in the text box, $(document).ready(function () { $("#company_name").key ...

How to update a timestamp field using MongoDB and the Golang driver

I am currently utilizing the official MongoDb Driver for Golang. Within my Golang code, there is a field with a timestamp type that I need to update. Below is the struct I am working with (the lastUpdate field is the timestamp field): import ( "conte ...

"Efficiently Browsing Through Various Links with the Help of Greasemon

My goal is to open approximately 25 hyperlinks from a single page. All of these hyperlinks include the text Free Win. I am looking for a solution that will open each individual link in a new tab within the browser. I have written a Greasemonkey script, ...

Got a not-a-number (NaN) value for the `children` prop in a

Just starting out with React and working on a type racer app. I've encountered an issue while trying to calculate WPM (Words per minute) - the calculation keeps returning 'NaN'. I've double-checked all the variables and ensured there ar ...

The jsPDF tool captures only the visible frame in a screenshot instead of printing the entire content on the screen

Recently, I integrated the jsPDF npm module into my Angular application to convert HTML to PDF. However, I encountered an issue where printing a website page to PDF only captures a screenshot of the visible area in Firefox and Chrome, as well as in Interne ...

Is there a way to store a class property as a variable using PostCSS?

Looking to store a dynamic property in a variable for use with calc(). There is a class with a height that changes dynamically. .cuerpo-detalle { height: x; } The goal is to create a variable that captures the height property of the .cuerpodetalle cla ...

I am interested in learning more about the Python requests.post method for sending data in JSON format and understanding how to receive a POST request from a PHP server

Python Script import json import requests temp_dict = {"user_id":"zed","user_password":"zed123","degrees":"23.5"} r=requests.post('https://localhost:8080/php/test.php',json = temp_dict ...

Is there a way to incorporate innerhtml (or innertext) with the h() function for adding content?

Due to certain requirements, I need to utilize virtual DOM. Below is the code snippet that I am working with: // test.js import { h, ref } from 'vue' const ButtonCounter = { name: 'button-counter', props: { tag: { type: S ...

Oops! Mongodb in vb.net: Your expression is not returning a value

Imports MongoDB.Bson Imports MongoDB.Driver Imports MongoDB.Bson.IO Snippet: Dim searchQuery = Query.EQ("name", "abc") Dim updateQuery = Update.Set("title", "rocks") Dim result As SafeModeResult = tblBooksCustom.Update(searchQuery, up ...