Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
This is a simple plugin to enable textsearch in your mongoose schema.
You can use this plugin just as any other mongoose plugin. For example for a blog post schema you would do something like that.
const mongoose = require('mongoose');
const textgoose = require('textgoose');
const postSchema = new mongoose.Schema({
title: String,
text: String,
author: String,
created_at: {type: Date, default: Date.now}
});
postSchema.index({title: 'text', text: 'text'});
postSchema.plugin(textgoose, options);
mongoose.model('Item', itemSchema);
Note that you need to mark the text fiels you want to use in search queries as indexes.
Also you can provide plugin with options
object. Here's what you can customize
language: string - the language of the queries. Default is en
.
Note that you need to mark your index field the same default_language
you use in plugin's options like that:
postSchema.index({title: 'text', text: 'text'}, {default_language: 'russian'});
caseSensetive: boolean - clarify if you want your searches to be case sesitive. Default is false
.
diacriticSensitive: boolean - clarify if you want your searches to be diacritic sensitive. Default is false
.
To use textgoose on your module write use textSearch
method like that.
Item.textSearch(query, queryOptions, (err, data) => {
if (err)
return console.log(err);
return res.send(data);
});
Queries are customizable too. You can use the following options.
filter: object - use this as additional filter for your database documetns. For examle you can filter your posts by author using this filter {author: "John"}
. Default is null
.
limit: number - defines the maximum documents returned by your database. Default is 100
.
scoreSort: boolean - If you want your docs to be sorted by their search score set it to true
. Default is false
.
FAQs
Mongoose plugin for full text search.
We found that textgoose demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.