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

Model.create with multiple documents

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None

      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...'
        }])
      

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

              Created:
              Updated:
              Resolved: