title: Creating a search query using Mongoose ORM
body: <p>I am trying to create a search query using Mongoose ORM. The search much be able to find part number, part description, or NSN number. However, I won't know which of the three the user is going to search for. I am not sure how to best implement this solution or if it is even possible with Mongoose.</p>
  
  <pre><code>let mongoose = require('mongoose');
  let mongooseUniqueValidator = require('mongoose-unique-validator');
  
  // Global variables
  let Schema = mongoose.Schema;
  
  // Define part schema
  let schema = new Schema({
      // _id: mongoose.Schema.Types.ObjectId,
      nsn: { type: String, trim: true, unique: true, minlength: 1 },
      partList: { type: String, trim: true },
      description: { type: String, trim: true },
      dataSheet: [{
          mrc: { type: String, trim: true },
          tipText: { type: String, trim: true },
          category: { type: String, trim: true },
          categoryDescription: { type: String, trim: true },
          url: { type: String, trim: true },
      }],
      category: { type: String, trim: true, minlength: 1 },
      subcategory: { type: String, trim: true, minlength: 1 },
      filter: { type: String, trim: true, minlength: 1 },
      url: { type: String, trim: true },
      createdAt: Date,
      updatedAt: Date
  })
  
  // plugin middleware
  schema.plugin(mongooseUniqueValidator);
  
  // create indexes
  schema.index({nsn: 'text', partList: 'text', description: 'text'});
  
  // Export schema
  module.exports = mongoose.model('Part', schema); ```
  
  
  
  
  ``` let searchString = req.params.search
  
      Part.find({$text: {$search: searchString}})
          .then(part =&gt; {
              if (part.length &gt; 0) {
                  res.json({
                      confirmation: 'success',
                      part: part
                  });
              } else {
                  res.status(204)
                      .json({
  
                      })
              }
          })
          .catch(err =&gt; {
              res.status(500)
                  .json({
                      confirmation: 'fail',
                      message: err.message
                  });
          }) ```
  </code></pre>