Limiting embedded item

32 views
Skip to first unread message

syful

unread,
Jun 22, 2012, 2:03:02 PM6/22/12
to mongodb-user
Hi,

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?

मैं एक भारतीय बेवकूफ हूँ

unread,
Jun 22, 2012, 2:55:08 PM6/22/12
to mongod...@googlegroups.com


syful wrote:
> Hi,
>
> I want to design a schema where post will not able to contain more
> than 10 tags.

Perform client-side validation and related actions...nothing where
MongoDB will help you directly.

Jenna

unread,
Jun 22, 2012, 6:15:08 PM6/22/12
to mongodb-user
You could include a counter field in the document, and when tags are
added, the field is incremented. This field allows you to prevent
updates if counter <10:

db.collection.update({_id: 1, counter : {$lt : 10}, tags: {$ne:
newTag}}, {$inc : {counter: 1}, $push : {tags: newTag}})


On Jun 22, 2:55 pm, "मैं एक भारतीय बेवकूफ हूँ"

Jenna

unread,
Jun 22, 2012, 6:21:28 PM6/22/12
to mongodb-user
Sorry for the typo; I meant you can prevent updates if counter > 10...

syful

unread,
Jun 23, 2012, 1:54:18 AM6/23/12
to mongod...@googlegroups.com
Thanks Jane

syful

unread,
Jun 23, 2012, 5:08:22 AM6/23/12
to mongod...@googlegroups.com
If its vice versa, like a post can have at most 10 tag and a tag can have at most 10 post then what can i do?
Thease are two different object.

Please reply a answer.

Thanks
Message has been deleted

Eliot Horowitz

unread,
Jun 24, 2012, 5:04:58 PM6/24/12
to mongod...@googlegroups.com
This is something you most likely need to handle client side.

On Sun, Jun 24, 2012 at 6:55 AM, syful <syful...@gmail.com> wrote:
> Nobody has the answer?
>
> --
> You received this message because you are subscribed to the Google
> Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com
> See also the IRC channel -- freenode.net#mongodb
Reply all
Reply to author
Forward
0 new messages