File: create.rb

package info (click to toggle)
ruby-mongo 2.21.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,764 kB
  • sloc: ruby: 108,806; makefile: 5; sh: 2
file content (33 lines) | stat: -rw-r--r-- 790 bytes parent folder | download
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
29
30
31
32
33
# frozen_string_literal: true
# rubocop:todo all

# Insert a document

require 'date'

result = client[:restaurants].insert_one({
    address: {
              street: '2 Avenue',
              zipcode: 10075,
              building: 1480,
              coord: [-73.9557413, 40.7720266]
             },
    borough: 'Manhattan',
    cuisine: 'Italian',
    grades: [
             {
               date: DateTime.strptime('2014-10-01', '%Y-%m-%d'),
               grade: 'A',
               score: 11
             },
             {
               date: DateTime.strptime('2014-01-16', '%Y-%m-%d'),
               grade: 'B',
               score: 17
             }
            ],
    name: 'Vella',
    restaurant_id: '41704620'
  })

result.n #=> returns 1, because 1 document was inserted.