Method: Mongo::Collection#insert
- Defined in:
- lib/mongo/collection.rb
#insert(doc_or_docs, options = {}) ⇒ ObjectID, Array Also known as: <<
Insert one or more documents into the collection.
256 257 258 259 260 261 |
# File 'lib/mongo/collection.rb', line 256 def insert(doc_or_docs, ={}) doc_or_docs = [doc_or_docs] unless doc_or_docs.is_a?(Array) doc_or_docs.collect! { |doc| @pk_factory.create_pk(doc) } result = insert_documents(doc_or_docs, @name, true, [:safe]) result.size > 1 ? result : result.first end |