Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5539

Find requires Pipeline aggregation to be coerced into an array

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 8.1.0, 8.0.4
    • Affects Version/s: 8.0.3
    • Component/s: Docs
    • None

        * mongo (2.18.2)
        * mongoid (8.0.3)
       
      From Working With Data > Aggregation Pipeline:

      band_ids = Band.collection.aggregate([
        { '$lookup' => {
          from: 'tours',
          localField: '_id',
          foreignField: 'band_id',
          as: 'tours',
        } },
        { '$lookup' => {
          from: 'awards',
          localField: '_id',
          foreignField: 'band_id',
          as: 'awards',
        } },
        { '$match' => {
          'tours.year' => {'$gte' => 2000},
          'awards._id' => {'$exists' => true},
        } },
        {'$project' => {_id: 1}},
      ])
      bands = Band.find(band_ids)
      

      I got an error:
       
      > /Users/george/.rbenv/versions/3.1.2/gemsets/trading-app-2/gems/bson-4.15.0/lib/bson/hash.rb:43:in `put_hash': Value does not define its BSON serialized type: #<Mongo::Collection::View::Aggregation:0x0000000116166b08> (BSON::Error::UnserializableClass)
       
      However, if I use #to_a, then it succeeds:
       
         bands = Band.find(band_ids.to_a)
       
      I'm not sure if this is desired behavior and the docs should be updated? Apparently it worked in the past so not sure...

            Assignee:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Reporter:
            george@boost-media.com George Ulmer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: