Is MongoDB still displaying results when the filter is set to false?

I am currently trying to retrieve data using specific filters. The condition is that if the timestamp falls between 08:00:00 and 16:00:00 for a particular date, it should return results. The filter for $gte than 16:00:00 is working correctly, but the $lte one is not.

Timestamp of work.time.work_time.start_time equals to 1680940800000

Timestamp of requestBooking.booking.estimated_start_time is 1680919200000

Here is the code snippet (it should fail, however surprisingly it is not failing).

      const bookingObject = await this.bookingRepository.findOne({
        user_id: body.worker_id,
        'work.date': requestBooking.booking.date,
        'work.time.work_time.start_time': {
          $lte: requestBooking.booking.estimated_start_time,
        },
        'work.time.work_time.end_time': {
          $gte: requestBooking.booking.estimated_start_time + 1800000, // Adding 30 minutes
        },
      });

Answer №1

Your usage of the operator is incorrect in this scenario. To ensure timestamps fall within a specific range, the start_time should be equal to or greater than and the end_time should be equal to or less than. You can achieve this by modifying your code as shown below:

const bookingObject = await this.bookingRepository.findOne({
        user_id: body.worker_id,
        'work.date': requestBooking.booking.date,
        'work.time.work_time.start_time': {
          $gte: requestBooking.booking.estimated_start_time,
        },
        'work.time.work_time.end_time': {
          $lte: requestBooking.booking.estimated_start_time + 1800000, // Adding 30 minutes
        },
      });

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

How to utilize *ngFor alongside the async pipe for conditional rendering in Angular 8 HTML

.html <ng-container *ngFor="let contact of listContact | async; let index = index;"> <h6 class="title" *ngIf="contact && contact['type']"> {{contact['type']}} </h6> <div> {{conta ...

Guide to implementing lazy loading and sorting in p-Table with Angular2

I recently implemented lazy loading in my application and now I am having trouble with sorting items. When lazy loading is disabled, the sorting feature works perfectly fine. However, I need help to make both lazy loading and sorting work simultaneously. C ...

Encountering an error message while trying to authenticate with Facebook using Passport: "Cannot read property '0' of undefined"

Currently working on integrating social authentication with Facebook into my app. Everything seems to be functioning properly up until the moment I attempt to log in using Facebook on my test app. Instead of being directed to the profile page, an error mes ...

Is it possible to continuously transfer information from MongoDB to Elasticsearch in real-time using NodeJS?

I'm looking to efficiently distribute the workload on my Database by retrieving data from ES and writing it to MongoDB. Is there a way to keep them in sync in real time? I've explored the Transporter library, but I need a solution that operates s ...

Using JavaScript, generate an array of objects that contain unique values by incrementing each value by 1

I have an array of objects called arrlist and a parameter uid If the property value has duplicate values (ignoring null) and the id is not the same as the uid, then autoincrement the value until there are no more duplicate values. How can I achieve the a ...

Using Angular to create a dynamic form with looping inputs that reactively responds to user

I need to implement reactive form validation for a form that has dynamic inputs created through looping data: This is what my form builder setup would be like : constructor(private formBuilder: FormBuilder) { this.userForm = this.formBuilder.group({ ...

What is the best way to delete an item (using its specific identifier) from an array within a mongoose/mongoDB model?

In my app, I have a User schema with a favorites key that stores an array of objects, each with a unique id. I am attempting to delete one of these objects based on its id. Here is the code snippet that I believe should accomplish this: User.updateOne({id ...

What is the best way to prevent users from entering a zero in the first position of a text box using JavaScript

Although I am aware this may be a duplicate issue, the existing solution does not seem to work for me. The field should accept values like: valid - 123,33.00, 100,897,99, 8000 10334 9800,564,88.36 invalid - 001, 0 ...

Enable Intellisense for my custom ES6 JavaScript modules in VS Code

Using VS Code Intellisense can greatly enhance productivity when working with internal project files, providing helpful autocompletion features and utilizing written JSDoc comments. However, my current projects involve custom JavaScript libraries stored i ...

What is the best way to save data from a Firebaselistobservable into an array?

I've been attempting to transfer data from Firebase to an array using Angular 2, but I'm facing difficulties in pushing the data into the array. Below is the code snippet: Variables: uid: string = ''; agencyItems: FirebaseListObserva ...

What is the process for an Angular Component to receive a return object from a service following an HTTP

I am currently working with angular 4. Is there a way to retrieve an object from a service in this framework? export class LoginRequest { username : string; password : string; } export class LoginResponse { token : string; message : string; sta ...

Error: While working in an Angular project, a TypeError occurs because the property '****' cannot be read when used within a forEach loop

As I attempt to iterate over this.data.members and perform certain actions within the forEach loop on this.addedUsers, I encounter a TypeError: Cannot read property 'addedUsers' of undefined. Interestingly, I can access this.data.members outside ...

The Angular translation service may encounter issues when used on different routes within the application

I'm currently working on an Angular application that has multi-language support. To better organize my project, I decided to separate the admin routes from the app.module.ts file and place them in a separate file. However, after doing this, I encounte ...

Javascript/Typescript Performance Evaluation

I am looking to create a visual report in the form of a table that displays the count of each rating based on the date. The ratings are based on a scale of 1 to 5. Below is the object containing the data: [ { "Date": "01/11/2022", ...

Having difficulty mastering the redux-form component typing

I am facing an issue while trying to export my component A by utilizing redux-form for accessing the form-state, which is primarily populated by another component. During the export process, I encountered this typing error: TS2322 Type A is not assignabl ...

Mastering the art of updating values using aggregate in MongoDB and Node.js

This question is specific to my particular situation. While there are many responses on the same topic, I have yet to find a solution. That's why I'm reaching out for assistance. Thank you. I am interested in being able to modify the lineItemS ...

The variable 'BlogPost' has already been declared within the block scope and cannot be redeclared

When working with Typescript and NextJS, I encountered the following Typescript errors in both my api.tsx and blogPost.tsx files: Error: Cannot redeclare block-scoped variable 'BlogPost'.ts(2451) api.tsx(3,7): 'BlogPost' was also dec ...

How do I select all checkboxes in TypeScript when I only click on one of them?

I'm currently working with a list of checkboxes in my HTML code: <div class="col-sm-12" *ngIf="ControllerModel"> <div *ngFor="let controller of ControllerModel" class="panel col-md-6 col-lg-6 col-xs-6"> <div class="panel-heading" ...

Serious issue: a dependency request is an expression (Warning from Angular CLI)

I am currently exploring the dynamic loading of lazy child routes within a lazy routing module. For example: const serverResponse = [ { path: "transaction", children: [ { path: "finance", modulePath: &qu ...

What is the best approach for defining variables in typescript?

Let's talk about creating a variable for a car: export class ICar { wheels: number; color: string; type: string; } So, which way is better to create the variable? Option one: const car = { wheels: 4, color: 'red', type: &apos ...