Search like keyword mongodb
NickName:Just Lovanto Ask DateTime:2022-12-18T23:08:59

Search like keyword mongodb

I got a problem when trying to create a search function in MongoDB, some articles that I read tell find just using a string, not a variable. I need to create a function that can search LIKE in SQL.

  async findAllLike(parameter, limit) {
    const ctx = "mongodb-findManyLike";
    const dbName = await this.getDatabase();
    const result = await mongoConnection.getConnection(this.config);
    if (result.err) {
      logger.log(ctx, result.err.message, "Error mongodb connection");
      return result;
    }
    try {
      const cacheConnection = result.data.db;
      const connection = cacheConnection.db(dbName);
      const db = connection.collection(this.collectionName);
      const recordset = await db
        .find({ title: { $search: parameter } })
        .sort({ createdAt: -1 })
        .limit(limit)
        .toArray();
      if (validate.isEmpty(recordset)) {
        return wrapper.error("Data Not Found , Please Try Another Input");
      }
      return wrapper.data(recordset);
    } catch (err) {
      logger.log(ctx, err.message, "Error find data in mongodb");
      return wrapper.error(`Error Find Many Mongo ${err.message}`);
    }
  }

Copyright Notice:Content Author:「Just Lovanto」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74842452/search-like-keyword-mongodb

More about “Search like keyword mongodb” related questions

Search like keyword mongodb

I got a problem when trying to create a search function in MongoDB, some articles that I read tell find just using a string, not a variable. I need to create a function that can search LIKE in SQL.

Show Detail

How to search on mongodb mongoose ObjectId per keyword?

How to search on mongodb mongoose _id ObjectId per keyword? Example in mysql SELECT * FROM `table` WHERE `id` LIKE '%keyword%' How can i achieve that in mongodb?

Show Detail

Text search in MongoDB, keyword search

I'm trying to do a keyword search in my mongoDB database. In the mongoDB console: db.logs.find({$text: {$search: 'key1'}}) gives the correct result. But when I use mongoose-text-search on my nodejs

Show Detail

How to implement keyword and location search with MongoDB?

I am trying to implement a web/smart phone app that allow users to search for places based on keywords and location and here is the requirement: Users shall be able to search by typing in keywords...

Show Detail

mongodb search by multiple tags

I am reading the mongoDB manual for searching by tags (elements in arrays); here is the page: http://docs.mongodb.org/manual/tutorial/model-data-for-keyword-search/ But, how do I search while using

Show Detail

JS partial Text Search in MongoDB

Env: MongoDB (4.0.6) At the beginning I was used regex search like this: keyword = new RegExp(keyword, 'img'); query.$or = [ { campaignTitle: keyword } ]; but main problem, "keyword" i

Show Detail

Sort by keyword index mongodb

I was wondering if there was a way to sort my mongodb results by the index of the search keyword. For example if I search the db by {name: da} i'll get back results like [{name: "yoda"},...

Show Detail

How do I search for a phrase and a keyword at the same time in mongodb?

Basically I'm going through a large yelp database in my mongodb, and I want to find all reviews with the phrase hot wings and keyword discount. But I can't create the right query that will look for...

Show Detail

Search data from 2 or more collection using search keyword in mongodb with Nodejs

I am getting data from 2 collections using keyword search in the child collection from mongodb. I am using aggregate function to set the lookup and search from the lookup. I tried inside the pipeline

Show Detail

MySQL query : search keyword like %

I was trying to query a database table by search keyword. My SQL is as follow: SELECT * FROM some_table WHERE some_name LIKE '%$keyword%' where $keyword is from PHP form POST data. The $keyword is

Show Detail