Method: Mongo::Collection#insert
- Defined in:
- lib/mongo/collection.rb
#insert(doc_or_docs, opts = {}) ⇒ ObjectId, ... Also known as: <<
Insert one or more documents into the collection.
377 378 379 380 381 382 383 |
# File 'lib/mongo/collection.rb', line 377 def insert(doc_or_docs, opts={}) doc_or_docs = [doc_or_docs] unless doc_or_docs.is_a?(Array) doc_or_docs.collect! { |doc| @pk_factory.create_pk(doc) } write_concern = get_write_concern(opts, self) result = insert_documents(doc_or_docs, @name, true, write_concern, opts) result.size > 1 ? result : result.first end |