talha-asad / mongoose-url-slugs

Create URL compatiable slugs on mongoose models, ensuring uniqueness.
MIT License
40 stars 22 forks source link

function that generate the slug #18

Closed RamyRais closed 8 years ago

RamyRais commented 8 years ago

Hello, I have already some document in the database and i am migrating ti use slug how can i update all my document so they have slug field?

I was looking for a function generate the slug something like URLSlugs.generate(text, options) and looping through all the document and generate it.

simison commented 8 years ago

Would just saving each document work?

Flower.findById(id, function (err, flower) {
  if (err) return handleError(err);

  flower.save(function (err) {
    if (err) return handleError(err);
    // Done, you should now have a slug
  });
});
RamyRais commented 8 years ago

I was using update and it seems with update it does not work but with save it work. Thank you.