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

Model.create with multiple documents

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:

      Description

      Unlike ActiveRecord, Mongoid doesn't support passing arrays in Model.create.

      Why?

      Just a sketch:

      def create_multiple(documents = [], options = {}, &block)
        docs = []
        documents.each do |doc|
          create(doc, options, &block)
        end
        docs
      end
       
       
      Post.create_multiple([
        { 
          title: 'Just another posts',
          body : 'Lorem ipsum dolor sit ame'
        },
        {
          title: 'Just another posts MONGOID-5',
          body : 'I want to tell you a story...'
        }])
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            zergetaev zergetaev
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: