qqilihq / mongoose-slugger Goto Github PK
View Code? Open in Web Editor NEWMongoose plugin to automatically generate so called slugs (atomically)
License: MIT License
Mongoose plugin to automatically generate so called slugs (atomically)
License: MIT License
The settings should have an optional maxAttempts
parameter, which allows to limit the number of retries in order to avoid long or endless loops.
I have encountered an issue with the "mongoose-slugger-plugin" where slugs are not being generated as expected. The plugin is supposed to generate unique slugs for Mongoose documents, but in my testing, I've found that non-unique slugs are being generated under certain circumstances.
I expect the "mongoose-slugger-plugin" to consistently generate unique slugs for Mongoose documents, even when conflicts exist.
Non-unique slugs are generated in some cases, leading to slug collisions.
import mongoose from "mongoose";
import { sluggerPlugin } from "mongoose-slugger-plugin";
const { Schema, model } = mongoose;
const schema = new Schema<any>(
{
userId: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: "User",
},
title: {
type: String,
required: true,
},
slug: {
type: String,
unique: true,
require: true,
},
description: {
type: String,
},
assets: {
type: [{ type: String, required: true }],
validate: {
validator: function (items: []) {
return items && items.length > 0;
},
message: "At least one asset is required",
},
},
},
{ timestamps: true }
);
schema.index(
{ slug: 1, title: 1, description: 1 },
{ name: "search", unique: true }
);
schema.plugin(sluggerPlugin, {
slugPath: "slug",
generateFrom: ["title"],
index: "search",
});
Please let me know if you need any additional information to investigate this issue.
Shippable currently shows something around 45 percent, but it should actually be 90 percent.
I am getting this error:
(node:5927) UnhandledPromiseRejectionWarning: MongoError: user is not allowed to do action [serverStatus] on [admin.]
Not sure why?
We're using atlas to host the mongodb
Can't install this now with latest mongoose at the package requires 5.0. Will it work with 6?
Like the title says, is this not supported?
const trip = await Trip.findOne({ _id: id, owner: userId }).exec()
trip.title = data.title
trip.description = data.description
await trip.save()
The slug remains the same.
It should be possible to configure a maximum length for the generated slugs. Ideas:
maxLength
parametermaxlength
validatorInstead of
export declare function wrap<D extends Document>(model: Model<D>): Model<D>;
… it should probably rather be …:
export declare function wrap<D extends Document, M extends Model<D>>(model: M): M;
So that it plays will e.g. with @casl/mongoose
.
The slugs I generate I don't want to necessarily be unique since they are accessed through another path /. However this plugin requires all slugs to be unique
Hello friends!
I am facing a problem when using with Typegoose, I am trying to allow users to create the same documents, but when using this plugin, I am getting error code 11000 when creating the document I am creating already existed before.
Here is my code, if I'm wrong please help me
Model.ts
Thank all!
See how we can automatically publish to NPM (probably based on the vX.Y.Z
tags?
See here:
nodkz/mongodb-memory-server#78
In this case, we cannot detect, where the duplicate exception happened. Can we add least add a check for the storage engine and show an error or warning to avoid any surprises here?
Should be possible through db.serverStatus().storageEngine
(see here). See here for the Node.js API.
One could stupidly do something like this:
schema.plugin(slugger.plugin, new slugger.SluggerOptions({
generator: (doc, attempt) => doc.whatever,
// …
}));
The generated slug would not change (as the attempt
is not considered) and produce an infinite loop (see also #2).
Add some checking logic, which verifies that the generated slug is actually unique before retrying.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.