@@ -20,20 +20,20 @@ class Collection
20
20
#
21
21
# @param [String, Symbol] name the name of the collection.
22
22
# @param [DB] db a MongoDB database instance.
23
- #
23
+ #
24
24
# @option opts [String, Integer, Symbol] :w (1) Set default number of nodes to which a write
25
25
# should be acknowledged
26
26
# @option opts [Boolean] :j (false) Set journal acknowledgement
27
27
# @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout
28
28
# @option opts [Boolean] :fsync (false) Set fsync acknowledgement.
29
- #
29
+ #
30
30
# Notes about write concern:
31
- # These write concern options will be used for insert, update, and remove methods called on this
32
- # Collection instance. If no value is provided, the default values set on this instance's DB will be used.
31
+ # These write concern options will be used for insert, update, and remove methods called on this
32
+ # Collection instance. If no value is provided, the default values set on this instance's DB will be used.
33
33
# These option values can be overridden for any invocation of insert, update, or remove.
34
34
#
35
35
# @option opts [:create_pk] :pk (BSON::ObjectId) A primary key factory to use
36
- # other than the default BSON::ObjectId.
36
+ # other than the default BSON::ObjectId.
37
37
# @option opts [:primary, :secondary] :read The default read preference for queries
38
38
# initiates from this connection object. If +:secondary+ is chosen, reads will be sent
39
39
# to one of the closest available secondary nodes. If a secondary node cannot be located, the
@@ -315,10 +315,10 @@ def find_one(spec_or_object_id=nil, opts={})
315
315
# @return [ObjectId] the _id of the saved document.
316
316
#
317
317
# @option opts [Hash] :w, :j, :wtimeout, :fsync Set the write concern for this operation.
318
- # :w > 0 will run a +getlasterror+ command on the database to report any assertion.
318
+ # :w > 0 will run a +getlasterror+ command on the database to report any assertion.
319
319
# :j will confirm a write has been committed to the journal,
320
320
# :wtimeout specifies how long to wait for write confirmation,
321
- # :fsync will confirm that a write has been fsynced.
321
+ # :fsync will confirm that a write has been fsynced.
322
322
# Options provided here will override any write concern options set on this collection,
323
323
# its database object, or the current connection. See the options
324
324
# for DB#get_last_error.
@@ -351,26 +351,29 @@ def save(doc, opts={})
351
351
# @option opts [Boolean] :j (false) Set journal acknowledgement
352
352
# @option opts [Integer] :wtimeout (nil) Set replica set acknowledgement timeout
353
353
# @option opts [Boolean] :fsync (false) Set fsync acknowledgement.
354
- #
354
+ #
355
355
# Notes on write concern:
356
356
# Options provided here will override any write concern options set on this collection,
357
- # its database object, or the current connection. See the options for +DB#get_last_error+.
357
+ # its database object, or the current connection. See the options for +DB#get_last_error+.
358
358
#
359
359
# @option opts [Boolean] :continue_on_error (+false+) If true, then
360
360
# continue a bulk insert even if one of the documents inserted
361
361
# triggers a database assertion (as in a duplicate insert, for instance).
362
362
# If not acknowledging writes, the list of ids returned will
363
363
# include the object ids of all documents attempted on insert, even
364
- # if some are rejected on error. When acknowledging writes, any error will raise an
364
+ # if some are rejected on error. When acknowledging writes, any error will raise an
365
365
# OperationFailure exception.
366
366
# MongoDB v2.0+.
367
367
# @option opts [Boolean] :collect_on_error (+false+) if true, then
368
368
# collects invalid documents as an array. Note that this option changes the result format.
369
369
#
370
- # @raise [Mongo::OperationFailure] will be raised iff :w > 0 and the operation fails.
370
+ # @raise [Mongo::OperationFailure] will be raised iff :w > 0 and the operation fails.
371
371
#
372
372
# @core insert insert-instance_method
373
373
def insert ( doc_or_docs , opts = { } )
374
+ if name . start_with? ( "system." ) && name !~ /(\A system\. users)|(\A system\. indexes)/
375
+ raise Mongo ::InvalidNSName , "cannot insert into system collections."
376
+ end
374
377
doc_or_docs = [ doc_or_docs ] unless doc_or_docs . is_a? ( Array )
375
378
doc_or_docs . collect! { |doc | @pk_factory . create_pk ( doc ) }
376
379
write_concern = get_write_concern ( opts , self )
@@ -392,7 +395,7 @@ def insert(doc_or_docs, opts={})
392
395
#
393
396
# Notes on write concern:
394
397
# Options provided here will override any write concern options set on this collection,
395
- # its database object, or the current connection. See the options for +DB#get_last_error+.
398
+ # its database object, or the current connection. See the options for +DB#get_last_error+.
396
399
#
397
400
# @example remove all documents from the 'users' collection:
398
401
# users.remove
@@ -446,7 +449,7 @@ def remove(selector={}, opts={})
446
449
#
447
450
# Notes on write concern:
448
451
# Options provided here will override any write concern options set on this collection,
449
- # its database object, or the current connection. See the options for DB#get_last_error.
452
+ # its database object, or the current connection. See the options for DB#get_last_error.
450
453
#
451
454
# @return [Hash, true] Returns a Hash containing the last error object if acknowledging writes.
452
455
# Otherwise, returns true.
@@ -631,7 +634,7 @@ def find_and_modify(opts={})
631
634
#
632
635
# @param [Array] pipeline Should be a single array of pipeline operator hashes.
633
636
#
634
- # '$project' Reshapes a document stream by including fields, excluding fields, inserting computed fields,
637
+ # '$project' Reshapes a document stream by including fields, excluding fields, inserting computed fields,
635
638
# renaming fields,or creating/populating fields that hold sub-documents.
636
639
#
637
640
# '$match' Query-like interface for filtering documents out of the aggregation pipeline.
0 commit comments