Relative Content

Tag Archive for node.jsmongodbmongoose

MongoDB – Search Collection after a string(with space) in node.js

const items = await ItemMongo.find({ itemhashname: { $regex: query, $options: ‘i’ } }).limit(10); currently I have this, the problem is that items in my collection looks like this “substring1 substring2 substring3” “substring1 substring4 substring5” “substring1 substring6 substring7” “substring8 substring2 substring9” when I input “substring1 substring2” into query, I want the result to be only “substring1 […]

Upgrade mongoose Version to latest

we are panning to upgrade our mongoose version from 5.12.0 to V8.4.1, our Mongo DB is V6.0.11 I understand that there are breaking changes related to callback and no more warning which we have taken care already. documentation suggests first go from 5x to 6x then 6x to 7x and 7x to 8x. which is very long and tedious as we have many services https://mongoosejs.com/docs/migrating_to_6.html#version-requirements https://mongoosejs.com/docs/migrating_to_7.html https://mongoosejs.com/docs/migrating_to_8.html await mongoose.createConnection(uri).asPromise(); I do not see anything related to schema update or issue with error If anyone has encountered issue during version upgrade? Should I go step by step as suggested in documentation?

Alphabetically sort mongodb result

const searchUser = asyncHandler( async (req: AuthenticatedRequest, res: Response, next: NextFunction) => { const { name = “” } = req.query; const users = await User.aggregate( [ { $match: { _id: { $ne: new Types.ObjectId(req.userId) }, }, }, { $match: { name: { $regex: name, $options: “i” }, }, }, { $sort: { name: 1 […]