Searching for an empty field in FireStore

I'm facing an issue with a query that searches for a gameCreatedAt equal to null. Even though the collection doesn't have any null values, it still retrieves data inexplicably!

Here is how the query is written:

const query = firestore().collection('matches')
  query.where('gameStartedAt', '==', null)
  query.where(`lobby.${uid}`, '>', 0)
  query.orderBy('createdAt', 'desc')
  query.limit(1)

And this is what the data looks like: https://i.sstatic.net/AfOfX.png

I am puzzled as to why the

query.where('gameStartedAt', '==', null)
condition appears to be silently dropped. I was hoping someone could shed light on this peculiar behavior. While the criteria works in other programming languages using something like NSNULL() as mentioned in this stackoverflow post, in JavaScript, null seems to just end up being ignored.

Answer №1

One issue is that the query method returns a new query object instead of modifying the original one (source).

To address this, you can simply remove query from each line, like so:

const query = firestore().collection('matches')
  .where('gameStartedAt', '==', null)
  .where(`lobby.${uid}`, '>', 0)
  .orderBy('createdAt', 'desc')
  .limit(1)

This adjustment should resolve the issue.

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

An obstacle prevents the code injection process in the Chrome extension when a button is pressed

My basic chrome extension is not functioning correctly. More specifically, I am encountering an issue where the alert box does not appear when I click on the button in the popup. Here are the contents of my manifest.json file: {"manifest_version": 2, "n ...

The type 'Observable<void | AuthError>' cannot be assigned to 'Observable<Action>'

I am encountering an error that reads: error TS2322: Type 'Observable<void | AuthError>' is not assignable to type 'Observable<Action>'. Type 'void | AuthError' is not assignable to type 'Action'. Type &a ...

The script encountered an error when attempting to access the property 'getContext' of a null object during the page's

window.onload = function() { var ctx = document.getElementById('chart-area').getContext('2d'); window.myDoughnut = new Chart(ctx, config); }; Upon loading the window, an issue occurred where the chart function was not working a ...

Ways to toggle the expansion and collapse of multiple divs efficiently with jQuery without duplicating code

I am trying to create a script that will expand and collapse a div containing a paragraph when the header text above it is clicked. <div class="container"> <h3><span class="toggler">Click here to toggle text</span></h3> <d ...

Revamp the Side Navigation Feature to Identify the Currently Viewed Section of the Page

My website currently features a side navigation bar that dynamically updates based on the user's scroll position. When the user reaches a specific height, a class is added to a div in the sidebar, turning it orange and indicating which part of the pag ...

Deliver a response to recipients through the "button" feature within the WhatsApp cloud API

I'm working on building a chatbot for my booking company. Here is an outline of my initial bot flow: const axios = require("axios").default; function initialize_bot(message, phone_number, access_token, sender, username) { if (message === ...

Implementing email validation on the view layer for the yii framework using JavaScript

<script type="text/javascript"> function validate() { var email = document.getElementById('email').value; var phone = document.getElementById('phone').value; var emailFilter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([ ...

Leveraging promises with node.js and couched/nano for asynchronous operations

Currently experimenting with the Q promises library in conjunction with couchDB and Nano. The code below is able to display messages in the console, however, it seems that the database is not being created as expected. var nano = require('nano') ...

What is the best way to verify if an XMLHttpRequest made to my public API originates from my own web application or from a third-party client in order to maintain priority?

Is there a method to determine on the API side whether a XMLHttpRequest is coming from my own web application (i.e. the JavaScript I developed) or from a third-party application? The issue appears to be that since the JavaScript runs on the client side an ...

The art of swift JavaScript currency conversion based on time

I am in need of transforming a collection of data containing expenses with different dates into an alternative currency. One challenge is that these expenses cover multiple years, so I must consider the changes in exchange rates over time. Does anyone kno ...

Angular.js provides a solution for parsing a unique structure of JSON array containing objects

How can an angular for each loop be used to handle the json array of objects provided in the formatted data below? The key represents the id and the value represents the title. Any suggestions on how to accomplish this task? Thank you. mycode me.record ...

Adjusting the dimensions of :before with JavaScript: A Step-by-Step Guide

There's this CSS3 tag named body:before that I'm working with, and I'm looking to adjust the height and width of body:before using JavaScript. Any suggestions on how to achieve this? ...

What is the best way to search for and isolate an array object within an array of objects using Javascript?

I am attempting to narrow down the list based on offerings const questions = [ { "id": 2616, "offerings": [{"code": "AA"},{"code": "AB"}]}, { "id": 1505, "offerings": [ ...

Retrieve the calculated events of an HTML element using JavaScript

Is there a way to retrieve the computed click events from an HTML object using JavaScript? I want to access the functions that are triggered when clicking on an HTML element. Is there a method to directly obtain the function calls instead of using the s ...

Maximizing the Potential of AngularJS with HTML Injections via Chrome Extensions

Is there anyone out there who has experience using AngularJS for Chrome extensions? If I wanted to insert a div into a page and have control over the layout and structure, what would be the best approach? I'm concerned about interfering with the par ...

Utilizing the useState hook to manage state

Is there a way to fetch the useState from another file in order to export sliderCount? Your assistance is greatly appreciated. I have two files. The first file utilizes the useState function and modifies the state upon button click. In the second file, I ...

Error encountered in React Material UI: Appbar - TypeError occurred when attempting to read properties that are undefined (specifically, reading '100')

Currently, I am working on developing a multi-step form using Material UI components. However, upon importing the necessary components, an error is being displayed in my code snippet: import React from 'react'; import { ThemeProvider } from &a ...

Learning about a basic sorting algorithm that analyzes and compares different values

While on the hunt for a simple jQuery sorting script, I stumbled upon this gem online: $(function() { $('ol').each(function() { var matches = $('li', this).filter(function() { // Each item var text = $(this).te ...

Is there a method to make .load work on Chrome?

Currently, I have a straightforward function that retrieves image data and then displays it. Following this, the script executes the sizeImages() function to resize the image in proportion to the browser size. The issue at hand is that this functionality ...

"An unexpected 'b' character was found at the beginning of the

I encountered the error "Unexpected token b in position 0" while trying to parse JSON returned from my PHP file in JavaScript. $file = array( array( 'src' => 'http://localhost/grapesjs-dev/uploads/'.$ ...