Find the location of $value in MongoDB where the timestamp is greater than or equal to JS

When attempting to find a nested element's existence and get a timestamp greater than a certain value, I'm encountering an issue:

 db.stats.find(  { $and:  [ { 'data.Statistics': {$exists: true} },{ timestamp: {$gte: 1} } ] }

Although consulting the documentation doesn't show any errors in my query structure. However, I am not receiving any results back.

Surprisingly, simply utilizing the following code snippet works for me:

var query = {};     
query["data.Statistics"] = {$exists: true} 

This approach seems to be effective in this case.

Answer №1

In this scenario, utilizing the $and operator may not be necessary because you can implicitly achieve the same result by simply listing expressions with commas. Thus, your query can be reformatted as follows:

db.stats.find({ 
    "data.Statistics": { "$exists": true },
    "timestamp": { "$gte": 1 } 
});

If you wish to use a variable to create the query object using square brackets, you can proceed as shown below:

var query = {};     
query["data.Statistics"] = { "$exists": true };
query["timestamp"] = { "$gte": 1 };

db.stats.find(query);

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

The functions isModified and isNew in Mongoose

In various tutorials, I have come across this particular example and it has raised a question in my mind. I am curious as to why this works with new documents. Could it be that new documents are automatically considered modified? Wouldn't it make more ...

Experiencing difficulty in successfully updating a React child component when the prop passed from the parent component is

In the backend implementation, I have successfully set up a socket.io, Node, Express configuration that has been tested to work correctly. It is emitting the right number of broadcasts to the appropriate client using socket.emit("team_set", gameI ...

Error: Unable to access 'author' property as it is undefined

Currently, I am in the process of learning how to create my own blog by following a tutorial on Github. The tutorial can be found at https://github.com/adrianhajdin/project_graphql_blog. However, while working with [slug].js to build localhost/3000/post/re ...

Remove background image when input form field is in focus

I am currently experimenting with the following approach: $('input').on('click focusin', function() { $('.required').hide(); }); However, it appears that this logic is not functioning as intended. Here is an ...

Vue.js is unable to dispatch an event to the $root element

I'm having trouble sending an event to the root component. I want to emit the event when the user presses enter, and have the root component receive it and execute a function that will add the message to an array. JavaScript: Vue.component('inp ...

Modify follow status once axios request is completed in Vue

I have a requirement to update the follow and unfollow button following an axios request. <template> <div v-if="isnot"> <a href="#" @click.prevent="unfellow" v-if="isfollowing" >unFellow</a> <a href="#" @cli ...

Issue of Vue not resolving Ionic back button component

I'm having trouble figuring out why Vue is giving me a warning and the back button isn't functioning as expected: runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Failed to resolve component: ion-back-button at <TheHeader titulo="Home&q ...

The dynamic sidebar menu in Adminlte 3 with bootstrap-4 loaded from ajax is not functioning properly, presenting issues with sidebar

Is there a way to fetch dynamic sidebar menu data from the database using AJAX in the adminlte 3 dashboard along with bootstrap 4? I have tried loading the sidebar menu data dynamically using AJAX, but the sidebar open/close functionality is not working pr ...

What's the most effective strategy for transforming and preserving a nested JSON file as a MongoDB record?

Dealing with a massive JSON file (about 1.8GB) that I want to utilize in an Express app has proven to be challenging, given that Node's import limit is set at 512MB. Despite being new to MongoDB and databases in general, it seems like transitioning to ...

Any ideas on how I can adjust this basic JSON to avoid triggering the "Circular structure to JSON" error?

Learning Journey I am currently teaching myself JavaScript and exploring JSON along the way. My current project involves developing a JavaScript WebScraper where I plan to store my results in JSON format. While I am aware of other methods like using data ...

Conceal the menu when tapping anywhere else

I am working on a project that involves implementing HTML menus that can be shown or hidden when the user interacts with them. Specifically, I want these menus to hide not only when the user clicks on the header again but also when they click outside of th ...

The functionality of a Vue custom tooltip behaves strangely after clicking the button multiple times

I created this custom tooltip code that automatically closes after 2 seconds when a user clicks on a button, not just hovers over it. Initially, it works perfectly for the first two clicks, but then starts behaving strangely from the third click onwards. ...

Building a personalized version with core-js

I am currently in the process of developing a custom build using core-js. Following the instructions provided, I initiated the following commands: npm i core-js && cd node_modules/core-js && npm i The process seemed to go smoothly. Then, ...

Adjust the input and transition the UI slider

Currently, I am facing an issue with two sliders and inputs. When the number in the top slider is changed, the number and slide in the bottom block do not update accordingly. What steps should I take to address this? $(document).ready(function() { var $ ...

I am on a quest to locate a specific key within an array of objects and then validate it using Regex

I've been struggling with this for over 3 days and still haven't found a solution. It feels like trying to find a needle in a haystack, but I'm determined to figure it out. My goal is to search for a specific key in an array of objects and ...

Run PHP code using JavaScript

I am currently using Windows and attempting to use JavaScript/PHP to call a specific form that is saved in a different location. The file D:\Test\Form.php has the following content: <form action="D:\Test\submit.php" method="post"&g ...

Displaying HTML elements in a specific order using ng-repeat

Upon receiving the json message, my goal is to display it in HTML in a specific order. Within the json message, the position value indicates the desired order of elements, with 0 representing the first element in the array. At times, the json message may ...

Tips for transferring the name field to a different page upon clicking

There are two pages in my project - the first one is called ItemMenuPage and the second one is called CartPage. The functionality I am trying to achieve is that when a user clicks on any item name on the ItemMenuPage, it should navigate to the CartPage, wi ...

Determine the estimated download duration using the $http protocol

I am experiencing an issue with a function that calculates the time it takes to download a text file (3MB in size) from my server. While it works well for single requests, when I attempt to run multiple requests simultaneously, the time spent waiting for a ...

String Representation of Mongoose Date Retrieval

Mongoose Model: const patientSchema = new mongoose.Schema({ firstName: String, middleName: String, lastName: String, addresses: [addressSubschema], dateOfBirth: Date, files: [{ type: mongoose.Schema.Types.ObjectId, ref: 'File&a ...