0

I want to design a schema where post will not able to contain more than 10 tags.

How could i achieve that?

Any one please help me?

1 Answer 1

0

This question is answered here: https://groups.google.com/group/mongodb-user/browse_thread/thread/b07397a005de86ed

1
  • The gist is that you can include a counter field for the embedded array, and limit updates to documents where the counter <10: db.collection.update({_id: 1, counter : {$lt : 10}, tags: {$ne: newTag}}, {$inc : {counter: 1}, $push : {tags: newTag}})
    – Jenna
    Jun 22, 2012 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.