Here's what you wrote, so it isn't lost in the void:
- (Hash, true) update(selector, document, opts = {})
Update one or more documents in this collection.
Parameters:
selector (Hash) — a hash specifying elements which must be present for a
document to be updated. Note: the update command currently updates only the
first document matching the given selector. If you want all matching
documents to be updated, be sure to specify :multi => true.
document (Hash) — a hash specifying the fields to be changed in the
selected document, or (in the case of an upsert) the document to be inserted
opts (Hash) (defaults to: {}) — a customizable set of options
Options Hash (opts):
:upsert (Boolean) — default: +false+ — if true, performs an upsert
(update or insert)
:multi (Boolean) — default: +false+ — update all documents matching
the selector, as opposed to just the first matching document. Note: only
works in MongoDB 1.1.3 or later.
:safe (Boolean) — default: +false+ — If true, check that the save
succeeded. OperationFailure will be raised on an error. Note that a safe
check requires an extra round-trip to the database. Safe options provided
here will override any safe options set on this collection, its database
object, or the current collection. See the options for DB#get_last_error
for details.
Returns: (Hash, true) — Returns a Hash containing the last error object if
running in safe mode. Otherwise, returns true.
Examples:
Scheduling::Task.collection.update({
'_type' => 'RecurringTask'
}, {:$set => {'_type' => 'Scheduling::RecurringTask'}}, {:multi => true})
Scheduling::Task.collection.update({
'_type' => 'CounterTask'
}, {:$set => {'_type' => 'Scheduling::CounterTask'}}, {:multi => true})
The following example illustrates how to rename fields through 'update'
command,
notice that old name and new name must be strings(symbols doesn't work)
MonitorProfile.collection.update({
:connections => { :$exists => true}
}, {
:$rename => {'connections' => 'connectivities'}
}, {
:multi => true
})
- (String) rename(new_name)
Rename this collection.
Note: If operating in auth mode, the client must be authorized as an admin to
perform this operation.
Parameters:
new_name (String) — the new name for this collection
Returns:
(String) — the name of the new collection.
Raises:
(Mongo::InvalidNSName) — if new_name is an invalid collection name.
Examples:
MonitorTask.collection.rename('scheduling_tasks')
When collection name is renamed, the name of corresponding model class is
usually renamed, so getting the
collection class through model class is not realistic, the following example
is based on MongoID:
Mongoid.master.collection(:monitor_tasks).rename(:scheduling_tasks)Version
1, updated 90 days ago.
. o 0 (
edit |
history )