-
Notifications
You must be signed in to change notification settings - Fork 534
/
Copy pathupdate.rb
28 lines (20 loc) · 1.39 KB
/
update.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true
# rubocop:todo all
# Update top-level fields in a single document
client[:restaurants].find(name: 'Juni').update_one('$set'=> { 'cuisine' => 'American (New)' },
'$currentDate' => { 'lastModified' => true })
# Update an embedded document in a single document
client[:restaurants].find(restaurant_id: '41156888').update_one('$set'=> { 'address.street' => 'East 31st Street' })
# Update multiple documents
client[:restaurants].find('address.zipcode' => '10016').update_many('$set'=> { 'borough' => 'Manhattan' },
'$currentDate' => { 'lastModified' => true })
# Replace the contents of a single document
client[:restaurants].find(restaurant_id: '41704620').replace_one(
'name' => 'Vella 2',
'address' => {
'coord' => [-73.9557413, 40.7720266],
'building' => '1480',
'street' => '2 Avenue',
'zipcode' => '10075'
}
)