import * as mongoose from 'mongoose';
const SALT_ROUNDS = 10;
function transformValue(doc, ret: { [key: string]: any }) {
delete ret._id;
delete ret.password;
}
export interface IUserSchema extends mongoose.Document {
organizationId: string;
email:string,
password:string,
userRole:[],
status:string,
firstName:string,
lastName:string,
address:string,
}
export const UserSchema = new mongoose.Schema<IUserSchema>(
{
organizationId:{
type: String
},
email:{
type: String,
},
password: {
type: String
},
userRole: {
type: []
},
firstName: {
type: String
},
lastName: {
type: String
},
address: {
type: String
},
status: {
type: String
},
},
{
toObject: {
virtuals: true,
versionKey: false,
transform: transformValue,
},
toJSON: {
virtuals: true,
versionKey: false,
transform: transformValue,
},
},
);
UserSchema.index({ "$**": "text" },
{ name: "userTextIndex",locale: 'en', strength: 2}) //
in Your Nest Js Mongo Config Service look like
import {
MongooseOptionsFactory,
MongooseModuleOptions,
} from '@nestjs/mongoose';
export class MongoConfigService implements MongooseOptionsFactory {
createMongooseOptions(): MongooseModuleOptions {
return {
uri: process.env.MONGO_DSN,
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
};
}
}
db.getCollection('user').find({ $text: { $search: "activ"} });
mongoose full text search in nestjs
mongodb full text search in nodejs
mongodb full $text $search in nodejs
mongoose create text indexes
No comments:
Post a Comment