Try to locate a particular sequence of characters

I am currently on a quest to locate a specific row within the database that corresponds to the message provided by the user, specifically: catalystname.

After successfully indexing the given string as text within the schema:


const { Schema } = mongoose;

const scheduleMessageSchema = new Schema({
    _id: { type: Schema.Types.Oid, auto: true },
    catalystname: String,
    catalystdesc: String,
    catalystquest: String,
    date: String,
});

scheduleMessageSchema.index({catalystname: 'text'});
module.exports = mongoose.model('dbcatalyst', scheduleMessageSchema);

Here is my search code:

const Catal = require("../src/models/dbcatalyst.js")


module.exports.run = async (client, message, args) => {

    message.content = args.slice(0).join(" ")

        Catal.find({$text: {$search: message.content}})
        .exec(function(docs){

        let embedlogs3 = new Discord.RichEmbed()
            .setAuthor(`1`, message.author.displayAvatarURL)
            .setDescription(`${docs}`)
            .setColor("#33ffff")

        message.channel.send(embedlogs3)
        /*/ ${collected.first().content}/*/
    });


}

Following this, I proceeded with locating the required line in the message. The bot effectively completes its task, yet displays the entire document instead of just 1 line.

_id: 5e243704961eb23c106bfb02,
catalystname: 'Чёрный Коготь',
catalystdesc: '0',
catalystquest: '0',
date: '1579430157018',
__v: 0
}

Is there a way to specifically output the string? catalystname

Answer №1

Upon reviewing the Mongoose documentation, it appears that the callback function requires two parameters:

  1. err: Indicates an error or null value
  2. docs: Represents the returned document(s)

To update your callback, consider using the following code snippet:

Catal.find({$text: {$search: message.content}})
  .exec(function(err, docs){
    ...
  });

By making this change, you should be able to retrieve an array containing the matching documents.

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

Turning the Three.js camera to the left and right side

My goal in Three.js is to create an orbiting camera that can be rotated around the x and y axes. I have implemented two functions to achieve this: function rotateX(rot) { var x = camera.position.x, y = camera.position.y, ...

The method expression does not match the Function type specified for the mongoose Model

Encountered a perplexing error today that has eluded my attempts at finding a solution. const mongoose = require('mongoose'); const userSchema = mongoose.Schema({ name: {type:String, required:false}, birthday: {type:String, required:f ...

Customize hoverIntent to support touch events on mobile devices

Hello everyone. I've encountered an issue with hoverintent.js, a jQuery plugin that handles mouseOver events differently than usual. I am facing constraints where I can only modify the JavaScript of this plugin, but I need it to be compatible with to ...

What is the process for incorporating Transformer instances into the buildVideoUrl() function using cloudinary-build-url?

This particular package is quite impressive, however, it seems to lack built-in support for looping gifs. Fortunately, the provided link demonstrates how custom URL sections like "e_loop" can be created. One challenge I'm facing is figuring out how t ...

Vuejs is throwing an error claiming that a property is undefined, even though the

I have created a Vue component that displays server connection data in a simple format: <template> <div class="container"> <div class="row"> <div class="col-xs-12"> <div class="page-header"> < ...

Dealing with Sequelize Errors

After reviewing the code provided, I am curious if it would be sufficient to simply chain one .catch() onto the outermost sequelize task rather than attaching it to each individual task, which can create a cluttered appearance. Additionally, I am wonderin ...

Events triggered by client-side interactions with ASP.NET controls

Below is the image code I'm working with: <asp:Image runat="server" ID="imgLogo" Style="border-width: 0px; max-width: 100%; max-height: 200px;" onerror="showInvalidImageMessage();" onload="imageChanged()"/> Even though I want to trigger a Java ...

Verify user identity before sending directory in Express

I'm encountering an issue with authenticating users before they access an express directory file tree. While I can successfully authenticate users on all other pages, I'm facing difficulties with authentication on "/dat/:file(*)" even though I ha ...

How to fetch React route parameters on the server-side aspect

I encountered a challenge while working with ReactJS and ExpressJS. The user uploads some information on the /info route using React and axios. Then, the user receives route parameters from the server side to redirect to: axios.post('/info', Som ...

Executing a function upon loading a page triggered by a submitted form

Recently on my index.php page, I implemented a form that posts data into a third-party newsletter system. After the form submission, the page reloads to index.php?mail&. Is there a way to detect when the page is loaded and determine if the form has bee ...

How can I trigger a jQuery click event from my ASP code behind?

The front end of this project has been completed and makes use of jQuery to handle user clicks. I have a radio button that triggers the event below when clicked. I want to ensure that this event is triggered for the HTML input element in my code behind dur ...

Retrieve the structure from a React application

When it comes to documenting architecture, the process can be incredibly beneficial but also quite time-consuming and prone to becoming outdated quickly. I have come across tools like Doxygen that are able to extract architectural details such as dependen ...

Gradient on multiple faces in Three.js

I'm currently struggling with creating an HSV cylinder using three.js. I am facing difficulties in properly mapping the gradient to the faces of the cylinder. Initially, I attempted to create my object in this manner: https://i.sstatic.net/WboAE.png ...

When you call setTimeout from a static function, it does not get executed

Having a problem with starting a timer in my utility typescript class. The static function initTimer() uses setTimeout but when called from a react component, the timer doesn't start. StyleWrapper.tsx const StyleWrapper: FC = (props) => { cons ...

Utilizing JQuery to Implement ngModel and ngBind in Angular Directives: A Step-by-Step Guide

[Note] My objective is to develop custom Angular directives that encapsulate all the necessary JS for them to function. The directives should not know what they are displaying or where to store user input values; these details will be passed in as attrib ...

Remove option from MUI Autocomplete after it has been selected

I am currently utilizing a Material-UI Autocomplete component. To avoid users selecting the same element twice, resulting in duplicate ID numbers, I want to remove the element from the dropdown entirely. For instance, if "Shawshank Redemption" is selected ...

search for a specific value within a nested subfield of an asterisk star field in Firestore

Here is the data I have: { root: { _rEG: { fen: 'value' }, _AS: { fen: 'value' }, _BSSA: { fen: 'value' } } } I would like to query using where('root.*.fen', '==', 'value'). ...

Error: The package is currently undefined in Grunt

When I run the command: The default task is concatenation. grunt -v I encounter the following Error message: Verifying property concat.dist exists in config...Warning: An error occurred while processing a template (pkg is not defined). Use --force to ...

Exploring the potentials of AngularJs Datatables Promise and the ignited power of Ignited

I am currently facing an issue with populating a datatable in AngularJS. DataTables warning: table id=DataTables_Table_0 - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.n ...

What adjustments can I make to my jQuery code in order to animate the mobile menu when it is initially clicked?

I have been using the following mobile menu code for some time now and it has been working well. I have implemented a CSS animation so that when the menu button is clicked, it smoothly scrolls into view. However, I have noticed that the animation does not ...