FAQ
Is this a new change? I started to notice this in the last week. Or, is
there something I totally misconfigured?

Thanks

Search Discussions

  • Arthur Neves at Jan 7, 2013 at 12:16 pm
    Can u post an example do clarify your question?

    Thanks

    --
    Arthur Neves

    On Monday, 7 January, 2013 at 12:42 AM, Learner wrote:

    Is this a new change? I started to notice this in the last week. Or, is there something I totally misconfigured?

    Thanks
  • Learner at Jan 7, 2013 at 11:27 pm
    I've created a new User but when I run User.last it doesn't show the most
    recently created User, but a user i've created a few days back. In the
    past its always been the last item in the collection. Let me know if I can
    provide more info. Thanks
    On Monday, January 7, 2013 4:16:27 AM UTC-8, Arthur Neves wrote:

    Can u post an example do clarify your question?

    Thanks

    --
    Arthur Neves

    On Monday, 7 January, 2013 at 12:42 AM, Learner wrote:

    Is this a new change? I started to notice this in the last week. Or, is
    there something I totally misconfigured?

    Thanks

  • Durran Jordan at Jan 8, 2013 at 8:13 am
    There are a lot of factors that would affect this. So I'll briefly explain
    the behavior of first/last in Mongoid and MongoDB.

    First of all, MongoDB does not guarantee any exact order in a collection,
    so issuing a query with limit -1 (essentially a "find one") is never
    guaranteed to return you the same document every time.

    With Mongoid, we wanted some sort of consistency here, so this is how we
    implemented #first and #last:

    For #first:
    1. If no sorting options exists on the criteria, or no default scope with
    sorting criteria exists, Mongoid adds an ascending sort to the query by _id.
    2. If sorting options exist on the criteria, or a default scope on the
    model exists with sort options, Mongoid applies no extra sorting.

    For #last:
    1. If no sorting options exists on the criteria, or no default scope with
    sorting criteria exists, Mongoid adds a descending sort to the query by _id.
    2. If sorting options exist on the criteria, or a default scope on the
    model exists with sort options, Mongoid reverses the sort order.

    So what I would suspect is that you've got some sorting applied, or check
    the ids in the collection.


    2013/1/8 Learner <cameronkendall444@gmail.com>
    I've created a new User but when I run User.last it doesn't show the most
    recently created User, but a user i've created a few days back. In the
    past its always been the last item in the collection. Let me know if I can
    provide more info. Thanks

    On Monday, January 7, 2013 4:16:27 AM UTC-8, Arthur Neves wrote:

    Can u post an example do clarify your question?

    Thanks

    --
    Arthur Neves

    On Monday, 7 January, 2013 at 12:42 AM, Learner wrote:

    Is this a new change? I started to notice this in the last week. Or, is
    there something I totally misconfigured?

    Thanks

  • Learner at Jan 14, 2013 at 2:42 am
    Thanks guys!
    On Tuesday, January 8, 2013 12:13:54 AM UTC-8, Durran Jordan wrote:

    There are a lot of factors that would affect this. So I'll briefly explain
    the behavior of first/last in Mongoid and MongoDB.

    First of all, MongoDB does not guarantee any exact order in a collection,
    so issuing a query with limit -1 (essentially a "find one") is never
    guaranteed to return you the same document every time.

    With Mongoid, we wanted some sort of consistency here, so this is how we
    implemented #first and #last:

    For #first:
    1. If no sorting options exists on the criteria, or no default scope with
    sorting criteria exists, Mongoid adds an ascending sort to the query by _id.
    2. If sorting options exist on the criteria, or a default scope on the
    model exists with sort options, Mongoid applies no extra sorting.

    For #last:
    1. If no sorting options exists on the criteria, or no default scope with
    sorting criteria exists, Mongoid adds a descending sort to the query by _id.
    2. If sorting options exist on the criteria, or a default scope on the
    model exists with sort options, Mongoid reverses the sort order.

    So what I would suspect is that you've got some sorting applied, or check
    the ids in the collection.


    2013/1/8 Learner <cameronk...@gmail.com <javascript:>>
    I've created a new User but when I run User.last it doesn't show the most
    recently created User, but a user i've created a few days back. In the
    past its always been the last item in the collection. Let me know if I can
    provide more info. Thanks

    On Monday, January 7, 2013 4:16:27 AM UTC-8, Arthur Neves wrote:

    Can u post an example do clarify your question?

    Thanks

    --
    Arthur Neves

    On Monday, 7 January, 2013 at 12:42 AM, Learner wrote:

    Is this a new change? I started to notice this in the last week. Or,
    is there something I totally misconfigured?

    Thanks

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmongoid @
categoriesmongodb, rubyonrails
postedJan 7, '13 at 5:42a
activeJan 14, '13 at 2:42a
posts5
users3
websitemongoid.org
irc#mongoid

People

Translate

site design / logo © 2022 Grokbase