When 'someField' is set to { $exists: true } in Mongoose, the database will retrieve a document even if 'someField' does not currently exist

Something peculiar is occurring with my Typescript code. Here's the snippet I'm running:

for await (const expression of Expression.find({'definiton': { $exists: true }}))
{
 console.log(Utils.stringize(expression))
}

Despite this, the output shows a document without the definition field:

{
  "_id": "63cc466d2c2338ef26205618",
  "labels": [
    "⊥"
  ],
  "author": {
    "userId": "63cc466c2c2338ef26205609",
    "username": "webmaster"
  },
  "timestampCreation": "2023-01-21T20:09:17.027Z",
  "tags": [
    "native symbol",
    "logic",
    "mathematics",
    "false"
  ],
  "nbrViews": 1,
  "nbrUsesInExpressions": 2,
  "nbrUsesInTruths": 0,
  "idsUsedExpressions": [],
  "idsUsedExtraAxioms": [],
  "type": {
    "sort": "P"
  },
  "parameters": [],
  "__v": 0
}

If you need more information, here is the Mongoose schema for the collection:

const expressionSchema = new Schema<IExpression>({
  labels: {
    required: true,
    type: [String],
    //unique: false,
    trim: true
  },
  author: {
    type: Schema.Types.Mixed, //Author,
    required: true,
  },
  //timestampCreation: Date,
  timestampCreation: {
    type: Date,
    required: true,
  },
  tags: {
    required: true,
    type: [String],
    trim: true
  },
  nbrViews: {
    required: true,
    type: Number,
  },
  nbrUsesInExpressions: {
    required: true,
    type: Number,
  },
  nbrUsesInTruths: {
    required: true,
    type: Number,
  },
  idsUsedExpressions: {
    type: [Schema.Types.ObjectId],
  },
  idsUsedExtraAxioms: {
    required: true,
    type: [Schema.Types.ObjectId],
  },
  type: {
    required: true,
    type: Schema.Types.Mixed //Sort|UnknownType|CompoundType
  },
  parameters: {
    type: Array
  },
  definition: {
    type: Schema.Types.Mixed //StatementBoundVariables,
  },
  idInstantiatedTruth: {
    type: Schema.Types.ObjectId,
  },
  idResultingTruth: {
    type: Schema.Types.ObjectId,
  }
})

I've attempted various approaches like 'definiton': { $ne: null } and

Expression.find().where('definiton').exists(true))
, but the issue persists. Any ideas on how to solve this?

Curious if anyone else has encountered this before.

Answer №1

There seems to be an inconsistency in the way you spell 'definition'.

While your schema file correctly defines it as 'definition', in your example query you have used 'definiton' (please note the missing 'i' before the last two characters).

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

Mongoose: Why does Model.save() not update the array of objects in my MongoDB collection?

I am facing an issue with my MongoDB where the data I'm trying to save specifically from an array is not being saved, while every other property is being saved normally. Below is my Schema: const mongoose = require('mongoose'); const SubS ...

Using AngularFire: How can you connect and bind data to the $scope efficiently?

Currently delving into the world of Firebase and noticing the differences between it and MongoDB. ...

oidc-client-js failing to display all profile claims that are supported by oidc-client-js

When setting up UserManager on the oidc-client-ts TypeScript module using the config object below: var config = { authority: "https://localhost:3000", client_id: "js", redirect_uri: "https://localhost:3001/callback.ht ...

Implementing atob in Angular's interface

Looking for a solution to a token storage issue, my initial thought is that interfaces might be the way to go. Presently, my login code looks like this: import { Component } from '@angular/core'; import { FormBuilder } from '@angular/forms&a ...

Ways to include various inputs with chip

I am currently working on a project that involves implementing an email field using the chip component. However, I have encountered an issue where pasting multiple email values for the first time inserts them into the field successfully. But when I try to ...

What is the best way to implement multiple templates for a single component?

Is there a way to configure my Home Component based on the user's role? For instance: If the employee is an admin, then the home component should load the template URL designed for admins. Likewise, if the employee is a cashier, then the home compo ...

Expand by focusing solely on recognized attributes?

I am working on creating an interface that can accept a mapped type, allowing for both runtime logic and compile-time typing to be utilized. Here is an example of what I'm aiming for: type SomeType = { a: string b: { a: string, b: string } } magi ...

Tips for implementing react-select types in custom component development

Currently, I'm in the process of developing custom components for DropdownIndicator to be used on react-select with Typescript. However, I am encountering difficulties with the component's type due to my limited experience with Typescript. I wou ...

Searching for abandoned nodes in a MongoDB tree structure - a comprehensive guide

I am managing the trees collection containing objects structured like trees. Currently, I am applying the child references pattern, but in my scenario, each tree's depth is not defined and can range from [0:100]: { "_id": "tree1" ...

Unable to connect to Alpine store from an external source due to a typescript error

Here is how I have configured my Alpine store: Alpine.store( 'state', ({ qr: '' })) Now, I am attempting to update it from an external source as follows: Alpine.store( 'state' ).qr = 'test' However, I am encounte ...

The aspect ratio of Threejs sprites is appearing distorted

I'm facing an issue with rendering two objects in an Orthographic camera using Three.js. The objects are not rendering correctly and I'm unsure of the reason behind it. The expected look of the two images is as follows: https://i.sstatic.net/hQ ...

I'm having trouble retrieving the value from the textbox in my Angular 7 project using TypeScript

I'm currently working with Angular 7 and trying to create a textbox to display its value in an alert. However, I'm facing difficulty in fetching the textbox value in typescript. I would appreciate any guidance on how to proceed with this issue. ...

Receiving a reply from the axios function

Whenever I try to call the lookUpItem function from ItemSearch.vue, I always get an undefined response. Code snippet from ItemSearch.vue: <script setup lang="ts"> import { lookUpItem } from '../systemApi' async fu ...

How to outsmart the TypeScript compiler when integrating a library without type definitions?

Is there a way to deceive the compiler into thinking that certain definitions are being used? My constructor contains: nv.addGraph(()=> {...}) Before my class declaration, I include: public nv:nv; In my model file, I define: export interface nv{ ...

Dividing the ZMQ socket from the express app.js by integrating with mongodb

Currently, I am working on an Express application that is responsible for gathering data sent from a remote machine through ZMQ and then updating a MongoDB database with this information. The data updates are transmitted every 5 minutes in the form of enc ...

Guide to Setting User Permissions with CheckboxList in MERN Stack

I have been working on implementing user permissions in MERN using a checkbox list. Initially, I tried manually granting access by using an if and else statement to give fixed authorization based on the user's role. Here's how it looks: {user.ro ...

The element 'imgAreaSelect' does not appear to be valid in this context

I came across an example, but it is not specifically for Angular. I attempted to create a project in angular 6 involving image area selection, but encountered the following error: .component.ts(64,16): error TS2339: Property 'imgAreaSelect' do ...

A versatile sorting algorithm

Currently, I am working on converting the material UI sorting feature into a generic type. This will enable me to utilize it across various tables. However, I have hit a roadblock in implementing the stableSort function, which relies on the getSorting func ...

The ArgsTable component is not displayed in Storybook when using Vite, Typescript, and MDX

I'm struggling to display the table with props on a MDX documentation page. No matter what I try, the table only shows: "No inputs found for this component. Read the docs >" Despite trying various methods, I can't seem to get it to work. I h ...

Tips for preserving user information after logging in with firebase authentication

Currently, I have implemented Firebase Authentication in my Angular application to enable users to log in. Here is the login() function within my AuthService: login(email: string, password: string) { return from(firebase.auth().signInWithEmailAndPassw ...