No data was retrieved by the Mongo query

I need help with a query to find all groups that have the subject of chemistry and match a specific user's schedule. The current query isn't returning any results, and I suspect there might be a syntax error in the code. I'm unsure of where I might be going wrong.

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const GroupSchema = new Schema({
  owner: {type: mongoose.Schema.ObjectId, ref: 'users'},
  subject: String,
  date: {type: Date, default: Date.now},
  mondayStart: Number,
  mondayEnd: Number,
  tuesdayStart: Number,
  tuesdayEnd: Number,
  wednesdayStart: Number,
  wednesdayEnd: Number
});

module.exports = Group = mongoose.model('groups', GroupSchema);


let query = Group.find({
  subject: '/chemistry/',
  $or: [
    {$and: [ {mondayStart: {gte: 6}}, {mondayEnd:  {lte: 8}}] },
    {$and: [ {tuesdayStart: {gte: 9}}, {tuesdayEnd: {lte:13}}] },
    {$and: [ {wednesdayStart: {gte: 9}}, {wednesdayEnd: {lte: 12}}
  ]
})

Answer №1

Make sure to update your search criteria. The following is an example of a functional query:

let searchQuery = School.find({
        topic: {$regex :'biology'},
      $or: [
        {$and: [ {mondayStart: {$gte: 7}}, {mondayEnd: {$lte: 9}}] },
        {$and: [ {tuesdayStart: {$gte: 8}}, {tuesdayEnd: {$lte: 12}}] },
        {$and: [ {wednesdayStart: {$gte: 8}}, {wednesdayEnd: {$lte: 11}}]}
        ]
    })

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 method JSON.stringify is not properly converting the entire object to a string

JSON.stringify(this.workout) is not properly stringifying the entire object. The workout variable is an instance of the Workout class, defined as follows: export class Workout { id: string; name: string; exercises: Exercise[]; routine: Ro ...

Deactivate click events in the container div

Here is the html code snippet that I am working with: <div class="parent" ng-click="ParentClick()"> . . . <div class="child" ng-click="ChildClick()"> Some Text </div> </div> When clicking on Som ...

In my React.js project, I am looking to iterate through an array of objects and organize them based on a specific condition

Here is an example of the structure of my JSON file: { "PlanetIdentifier": "KOI-1843.03", "TypeFlag": 0, "PlanetaryMassJpt": 0.0014, "RadiusJpt": 0.054, "PeriodDays": 0.176891 ...

A guide to exporting a PDF in A4 size landscape mode with jspdf

As a novice in UI development, I am currently trying to export HTML content to PDF using the JSPDF library. However, I have encountered difficulties in generating the PDF in A4 size landscape mode. The HTML code includes data with charts (canvasjs/chartjs) ...

How come I am unable to reach the window in my Next.js application's '_app.js' file?

In my Next.js application, I am trying to implement a feature where the app loads and then checks for network access using a custom modal dialog that alerts the user if they lose internet connection. I have set up an _app.js file in my application to estab ...

Error in Firebase admin SDK FCM: Only one of the parameters topic, token, or condition is mandatory

I encountered an error message while trying to send FCM notifications with multiple tokens. This was working fine before, but now I'm getting the following error: 0|api | 2020-2-11 13:26:26 [ExceptionsHandler] Exactly one of topic, token or co ...

Ways to have a function return a promise from the final "then" in a series of promises

I am delving into the world of test automation with Selenium and JavaScript. As a newcomer to both, along with functional programming and promises, I am facing a challenge in creating a function that performs three essential tasks: Click on an input Clea ...

Using jQuery to replace the content of a div with a delay?

I am attempting to utilize jQuery to create a fade effect on an element, replace its innerHTML content, and then fade it back in once the new content has been added. I have successfully managed to replace the element's content using the .html() method ...

Mastering the art of updating objects with React's useState() function

Having trouble updating my state using useState(). Whenever the alert pops up, it shows the initial value of my state. Below is a sample code snippet. I expect that when I click the Save button, setData should update data with the new form values, then di ...

Assigning a CSS class during the $routeChangeStart event does not activate the animation, unless it is placed within a setTimeout function

Just dipping my toes into Angular, so feel free to correct me if I'm way off base here. I've been working on animating the clamps on both sides of my website to slide in upon the initial page load. You can check out the live version at: Current ...

Arranging the properties of an object following the reduction process

I am currently working on replicating the functionality of an Outlook mailbox by organizing a list of Outlook emails based on their conversation ID. However, I am facing the challenge of needing to sort my list twice - once to order the emails in each grou ...

Here is a step-by-step guide on creating a custom select all checkbox in the toolbar of a MUI

I am currently using the MUI data grid to build my table, with the following properties: <DataGrid rows={serialsList || []} columns={columns} rowsPerPageOptions={[25, 50, 100]} //pageSize={93} ...

What is causing req.params.id to be undefined?

After diving into the world of microservices in Nodejs, I decided to create two standalone microservices named auth and users, each running on different ports. The auth service is responsible for handling user creation and log-in functions using a usernam ...

Utilizing AngularJS $anchorScroll for navigating to an anchor tag on a different page

On my AngularJS Home Page, I am trying to scroll to an anchor tag on another page. Both pages are loaded as partial html files into the ng-view component based on the URL. When I start the server, the home page loads and then I need to navigate to the FAQ ...

Validate if the user is actively scrolling; if not, automatically adjust the scroll position to the bottom

I am currently developing a chat site where the chat box updates every 200 milliseconds. I have managed to reposition the scrollbar to the bottom when a new message is loaded. However, I encountered a problem - whenever a user tries to scroll to the top, t ...

Placing JavaScript at the bottom of the page, sourced from a Partial Page

I'm trying to display JavaScript code from a Razor Partial Page at the bottom of a (layout) Page. In a similar discussion on Stack Overflow about Including JavaScript at bottom of page, from Partial Views, it was suggested by user Becuzz that using a ...

Angular Date Filtering to Show dd-mm-yyyy Format

I am having trouble filtering the date correctly in my controller. My desired date format is Thu Mar 31 2016 05:05:00 GMT-0400 (EDT). However, when I use the code mentioned above, the results show up as 03-31-2016. This is the code snippet from my contr ...

Loop over elements retrieved from Firebase using ng-repeat

I am currently attempting to iterate through items retrieved from Firebase using ngrepeat. Although I can see the items in the console, the expressions are not working as expected. I have tried various solutions, but nothing seems to be working. Any assist ...

What's causing the unexpected rendering outcome in Three.js?

Here is a mesh created in Blender: https://i.sstatic.net/KBGM5.jpg Upon loading it into Three.js, I am seeing this result: https://i.sstatic.net/PCNQ8.jpg I have exported it to .obj format and ensured all faces are triangulated. I am not sure why this is ...

Instructions for developing an HTML element slider using mouse dragging

I've come across plenty of slider plugins that either only allow clicking to view the next image, or if they do support mouse drag or touch capabilities, they are limited to images. Does anyone know of a plugin or method to create a mouse drag slider ...