
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
@cme-pro/mongoose-search
Advanced tools
Mongoose schema plugin to search on multiple fields. Support search on ObjectID, Regex or Mongodb text indexes
Mongoose schema plugin to search on multiple fields. Supports:
There are already multiple plugins to manage search, but most of them are handling too much (like filtering or pagination). This plugin only build the query related to a fulltext search, and let other plugins handle their part (pagination, ...).
$ npm install @cme-pro/mongoose-search --save
or
$ yarn add @cme-pro/mongoose-search
const mongoose = require("mongoose");
const mongooseSearch = require("@cme-pro/mongoose-search");
const { Schema } = mongoose;
const BlogPost = new Schema({
title: { type: String, searchable: true },
body: { type: String, searchable: (q: string) => new RegExp(`${q}`) },
excerpt: { type: String }
});
BlogPost.index({ title: "text", body: "text" });
const BlogPostModel = mongoose.model("Post", BlogPost);
Simple search:
const query = BlogPostModel.searchQuery("reactjs");
/**
query = {
$or: [
{
$text: { $search: "reactjs" }
},
{
title: /^reactjs/
},
{
description: /reactjs/
}
]
}
*/
Search on ObjectID:
const query = BlogPostModel.searchQuery("5cfa2debabe4d93a5b35897c");
/**
query = { $_id_: "5cfa2debabe4d93a5b35897c" }
*/
Custom search
const query = BlogPostModel.searchQuery("reactjs", { fields: { title: true } });
/**
query = {
$or: [
{
$text: { $search: "reactjs" }
},
{
title: /^reactjs/
}
]
}
*/
FAQs
Mongoose schema plugin to search on multiple fields. Support search on ObjectID, Regex or Mongodb text indexes
We found that @cme-pro/mongoose-search demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.