You could also keep an array of views embedded in each user but that
will not perform well if they are viewing lots of new things,
constantly.
How many things can they view as compared to the number of users? How
often will they be viewing something new versus updating their last
viewed time?
> --
> 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.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>
It still might be best to just keep that flat collection if you want
historical information, other that the latest 10.
No, but you can do yourself, and replace it with the feature when it
comes out (in a few months).
>
> By flat you mean 1 row/document per set of data, so user a, user b,
> timestamp type thing?
Yes, you can either do an update w/upsert, or just insert a new one
each view. An index will help return the latest 10, quickly.
set != ordered/sorted.
You can $pull + $push, since you want to replace the item. That will
allow you to maintain set-like behavior, with newest at the bottom.
> Since I am also very interested in implementing this use case in my own web
> site, I have raised a jira requesting $pushToSet which would do
> that: http://jira.mongodb.org/browse/SERVER-2362. Votes will help it get
> scheduled sooner :)
This seems pretty complicated. A lot this should be handled with
virtual collections and the ability to $addToSet/$push/$pushAll to the
top, or bottom (current behavior).
> If you follow Scott's advice and do this yourself for now then it would
> probably be best to have a single array of visitors in one document per
> profile instead of document per visit - much less to change later.
Yes, I was suggesting you keep the last 10 visitor list in the user/profile.
> The flat option Scott suggested would probably be faster for inserts, and so
> that may be the only one you can make work in the interim, depending on your
> traffic.
This will produce *much* more data, and should be cheaper on insert
but at the cost of more expensive indexes.
On Sat, Jan 15, 2011 at 11:06 AM, Keith Branton <ke...@branton.co.uk> wrote:set != ordered/sorted.
> Even with http://jira.mongodb.org/browse/SERVER-991 you would still need a
> modifier that doesn't exist. A way of pushing to an array while maintaining
> set semantics - so your new item always appears at the end of the set
> regardless if it was in there previously.
You can $pull + $push, since you want to replace the item. That will
allow you to maintain set-like behavior, with newest at the bottom.
This seems pretty complicated. A lot this should be handled with
> Since I am also very interested in implementing this use case in my own web
> site, I have raised a jira requesting $pushToSet which would do
> that: http://jira.mongodb.org/browse/SERVER-2362. Votes will help it get
> scheduled sooner :)
virtual collections and the ability to $addToSet/$push/$pushAll to the
top, or bottom (current behavior).
Yep, I was just pointing out that sets don't *need* to be ordered. I
wasn't trying to nit-pick, but just make it clear that that wasn't an
assumption my answers included.
>>
>> You can $pull + $push, since you want to replace the item. That will
>> allow you to maintain set-like behavior, with newest at the bottom.
>
> No I can't. Not in one isolated operation - I get a "Field name duplication
> not allowed with modifiers" error when I try this in the shell. At that's
> what I get in 1.7.4.
Yes, there is an outstanding bug: http://jira.mongodb.org/browse/SERVER-1050
>> > Since I am also very interested in implementing this use case in my own
>> > web
>> > site, I have raised a jira requesting $pushToSet which would do
>> > that: http://jira.mongodb.org/browse/SERVER-2362. Votes will help it get
>> > scheduled sooner :)
>>
>> This seems pretty complicated. A lot this should be handled with
>> virtual collections and the ability to $addToSet/$push/$pushAll to the
>> top, or bottom (current behavior).
>>
>
> Should? perhaps, yet these operations are not specified
> on http://jira.mongodb.org/browse/SERVER-142. In fact pretty much nothing is
> specified beyond db.foo.$bar.find(). I have to be honest I don't even know
> what that means. It is not scheduled, despite having a huge number of votes
Yeah, it does seem to pointed to like a magic bullet but without any
specification. I feel like the lack or implementation isn't because it
isn't well understood or conceptualized but because it will change a
lot of how things work internally.
> (which suggests it lacks specification) and depends on another unscheduled
> task. I'm not holding my breath for that golden hammer until I understand
> what it really is!
As well you shouldn't; unless you amazing lungs.
> No offence intended, but you seem to have missed the main point - with add
> to set new items are not added (or moved) if they already exist. With
No, I get it but my point is that ordering doesn't matter for meeting
a set requirement. Why should there be a restriction that they stay in
the same ordinal position? That my be a side effect of the
implementation, but it isn't a requirement.
> $pushToSet the idea is to treat the array like both a set (like $addToSet
> does) and a stack (like $push does) - the new items will always appear at
> the end. If the array already includes one of the new items then it would be
> removed first. Nothing you are suggesting would achieve this.
If you could $pull + $push (since the $addToSet doesn't mean much at
that point) would that not achieve your goal?
> If it seems complicated then perhaps my explanations are not as clear as
> they should be, as they are very simple variations of existing features imo.
> If you can point out where the complexity is I'd be happy to try again!
I'll add some comments to the issue :)
> Regards,
> Keith.
Yep, I was just pointing out that sets don't *need* to be ordered. I
wasn't trying to nit-pick, but just make it clear that that wasn't an
assumption my answers included.
Yes, there is an outstanding bug: http://jira.mongodb.org/browse/SERVER-1050
> $pushToSet the idea is to treat the array like both a set (like $addToSetIf you could $pull + $push (since the $addToSet doesn't mean much at
> does) and a stack (like $push does) - the new items will always appear at
> the end. If the array already includes one of the new items then it would be
> removed first. Nothing you are suggesting would achieve this.
that point) would that not achieve your goal?