The data returned by MongoDB's .find() method is not accurate

My challenge lies in extracting data from MongoDB, but every time I attempt to use the find() function, I encounter the following response. Being a novice in Mongo, I'm puzzled by why this issue is occurring. The code is written in TypeScript and is being utilized to develop a Discord bot.

Query {
  _mongooseOptions: {},
  _transforms: [],
  _hooks: Kareem { _pres: Map(0) {}, _posts: Map(0) {} },
  _executionStack: null,
  mongooseCollection: Collection {
    collection: null,
    Promise: [Function: Promise],
    modelName: 'verifiedUsers',
    _closed: false,
    opts: {
      autoIndex: true,
      autoCreate: true,
      schemaUserProvidedOptions: {},
      capped: false,
      Promise: [Function: Promise],
      '$wasForceClosed': undefined
    },
    name: 'verifiedUsers',
    collectionName: 'verifiedUsers',
    conn: NativeConnection {
      base: [Mongoose],
      collections: [Object],
      models: [Object],
      config: {},
      replica: false,
      options: null,
      otherDbs: [],
      relatedDbs: {},
      states: [Object: null prototype],
      _readyState: 0,
      _closeCalled: false,
      _hasOpened: false,
      plugins: [],
      id: 0,
      _queue: [],
      _listening: false
    },
    queue: [],
    buffer: true,
    emitter: EventEmitter {
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      [Symbol(kCapture)]: false
    }
  },
  model: Model { verifiedUsers },
  schema: Schema {
    obj: { ign: [Object], memberid: [Object] },
    paths: {
      ign: [SchemaString],
      memberid: [SchemaString],
      _id: [ObjectId],
      __v: [SchemaNumber]
    },
    aliases: {},
    subpaths: {},
    virtuals: { id: [VirtualType] },
    singleNestedPaths: {},
    nested: {},
    inherits: {},
    callQueue: [],
    _indexes: [],
    methods: {},
    methodOptions: {},
    statics: {},
    tree: {
      ign: [Object],
      memberid: [Object],
      _id: [Object],
      __v: [Function: Number],
      id: [VirtualType]
    },
    query: {},
    childSchemas: [],
    plugins: [ [Object], [Object], [Object], [Object], [Object] ],
    '$id': 1,
    mapPaths: [],
    s: { hooks: [Kareem] },
    _userProvidedOptions: {},
    options: {
      typeKey: 'type',
      id: true,
      _id: true,
      validateBeforeSave: true,
      read: null,
      shardKey: null,
      discriminatorKey: '__t',
      autoIndex: null,
      minimize: true,
      optimisticConcurrency: false,
      versionKey: '__v',
      capped: false,
      bufferCommands: true,
      strictQuery: true,
      strict: true,
      pluralization: true
    },
    '$globalPluginsApplied': true
  },
  op: 'find',
  options: {},
  _conditions: {},
  _fields: undefined,
  _update: undefined,
  _path: undefined,
  _distinct: undefined,
  _collection: NodeCollection {
    collection: Collection {
      collection: null,

The code snippet in use is as follows: Schema:

import mongoose from 'mongoose'

const verifiedUsers = new mongoose.Schema({
    ign: {
        type: String,
        required: true
    },
    memberid: {
        type: String,
        required: true
    },
})

export default mongoose.model('verifiedUsers', verifiedUsers, 'verifiedUsers')

get Verified Users:

import mongoose from 'mongoose'
import verifiedUsers from './schemas/verified-users'

client.on('ready', async () => {
    await mongoose.connect(
        process.env.mongo_uri || '',
        {
            keepAlive: true
    })
})

async function getVerifiedUsers() {
    console.log(verifiedUsers.find())
}
getVerifiedUsers()

What could be causing this issue and how can it be rectified?

Answer №1

If you encounter this issue, make sure to utilize the .exec() method.

For further guidance, refer to Model.find() and also consider checking out this helpful answer.

It might be interesting to discuss why using .find() doesn't automatically retrieve the data instead of requiring .exec().

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

Develop a user interface designed specifically for a subset of JSX.Elements or ReactElement

For better organization, I decided to create an interface called IconInterface to group all my icons: import { IconProps, CaretProps, CheckboxProps } from "./IconProps"; interface IconInterface { (props: IconProps | CaretProps | CheckboxProp ...

I am looking for a connection string that can be used with Parasoft tool or Java to connect to a Mongo Db database with LDAP authentication

Attempted using MongoClient for connecting without authentication with the following connection string, but it does not work for LDAP authentication. MongoClient client = new MongoClient("mongodb://username:pass@localhost/portnumber") Is there a specific ...

Next.js's router.push method directs the user to the specified URL and refreshes the page

I am facing an issue with my page structure: pages [re] login [slug.tsx] When I navigate from http://localhost:3000/in/login/data1 to http://localhost:3000/in/login/data2 using router.push on button click, the route is updated but th ...

Using properties to generate a header component in TypeScript

I am currently exploring TypeScript and incorporating it into a project for the first time. I'm encountering a challenge as I am not sure what to call this concept, making it difficult to search for solutions. If someone can provide me with the term, ...

Is it feasible to obtain the userId or userInfo from the Firebase authentication API without requiring a login?

Is it feasible to retrieve the user id from Firebase authentication API "email/password method" without logging in? Imagine a function that takes an email as a parameter and returns the firebase userId. getId(email){ //this is just an example return t ...

Obtain the type of a Typescript interface property by only providing the property name

Within my Typescript interface, there are numerous properties. In the absence of any instance of this interface, I aim to identify the type of a specific property. export interface Data { foo: string; bar: number; . . . } One way to achieve thi ...

Parent composition failing to receive emissions from Vue3 child component

Recently started learning vue and exploring event handling between Children and Parents. I've developed a child component with an emit exposed in the script setup: const emit = defineEmits(['OnTileClicked']) function TileClicked() { ...

What is the best method to update all the values of an array within a MongoDB document?

Suppose I have a newly created string array, called arr, and I want to replace an existing array in a mongoDB document by accessing it through a string component of the mongoDB document. How can I achieve this? Here is the code I have attempted so far, bu ...

Unable to see PrimennGTreeTable icon

While utilizing the PrimeNG TreeTable component, I am facing an issue where the expand/collapse icon is not visible in my code. You can check out the documentation at https://www.primefaces.org/primeng/#/treetable I suspect that the problem lies with the ...

What is the most effective way to compare two arrays of objects in JavaScript?

I'm working on a function that needs to return an array of elements based on certain filters. Here is the code for the function: filter_getCustomFilterItems(filterNameToSearch: string, appliedFilters: Array<any>) { let tempFilterArray = []; ...

The instantiation of generic types in Typescript

I have been working on a function that aims to create an instance of a specified type with nested properties, if applicable. This is the approach I have come up with so far. export function InitializeDefaultModelObject<T extends object> (): T { ...

A parameter in Typescript must be provided if another parameter is set to true

Need help with TypeScript function parameters: myFunction(allData: Array<any>, selectedItems: Array<any>, onlyValues: boolean = false, values: Array<any>) { console.log(allData); console.log(selectedData); console.log(onlyValu ...

Tips for displaying a view in Express while also sending a JSON object at the same time

I have encountered an issue that I need help solving. Currently, in ExpressJS 4, I am utilizing Jade as the template engine and AngularJS as the client-side framework. Through the mongoose module, I am retrieving a list of car brands from my MongoDB data ...

What is the best way to get my Discord bot to respond in "Embed" format using TypeScript?

I've been attempting to create a bot that responds with an embedded message when mentioned, but I'm running into some issues. Whenever I run this code snippet, it throws an error in my terminal and doesn't seem to do anything: client.on(&apo ...

There is no matching signature for Type when using withStyles

Struggling to convert my React App to typescript, I keep encountering the error below and cannot decipher its meaning. The app functions perfectly in plain JS. My package version is material-ui@next TS2345: Argument of type 'typeof ApplicationMenu&a ...

Ways to indicate in Typescript that a value, if it exists, is not undefined

Is there a way to represent the following logic in TypeScript? type LanguageName = "javascript" | "typescript" | "java" | "csharp" type LanguageToWasmMap = { [key in LanguageName]: Exclude<LanguageName, key> ...

Linking key value pairs through a TypeScript interface

coding interface StoreActions { setUserName: string actionOne: string[] actionTwo: { testValue: string } } interface CustomActions extends AnyAction { typeOfAction: keyof StoreActions // additionalData:??? } The attribute typ ...

What could be causing the TypeScript type error within this Effector effect subscriber?

Working on a front-end application utilizing React, Typescript, Effector, FetchAPI, and other technologies. Created an Effector effect to delete an item in the backend: export const deleteItemFX = createEffect({ handler: (id: string) => { return ...

Determine if the grid is accurately sorted in sequence using Cypress

I am currently working on sorting images based on their order, with the options for new and old. The [data-cy="list-file"] wraps all the images, while [data-cy=fileCard-list] represents each individual image. After selecting the 'old' b ...

Error: The function call does not match any of the overloads. 'VueRouter' is not recognized

I'm new to TypeScript and currently trying to implement vue-router in my project. Encountering the following errors: Error TS2769: No overload matches this call in source\app\main.ts(3,3). Overload 1 of 3, '(options?: ThisTypedCompon ...