Skip to content

Commit

Permalink
documentdb
Browse files Browse the repository at this point in the history
  • Loading branch information
omenking committed Apr 11, 2024
1 parent 29c9a91 commit bd36d25
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
8 changes: 8 additions & 0 deletions documentdb/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

source "https://rubygems.org"

# gem "rails"
gem 'ox'
gem 'mongo'
gem 'pry'
24 changes: 24 additions & 0 deletions documentdb/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GEM
remote: https://rubygems.org/
specs:
bson (5.0.0)
coderay (1.1.3)
method_source (1.0.0)
mongo (2.20.0)
bson (>= 4.14.1, < 6.0.0)
ox (2.14.18)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
mongo
ox
pry

BUNDLED WITH
2.5.6
24 changes: 24 additions & 0 deletions documentdb/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

## Mongo Shell Ubuntu (Jammy)

Get version of ubuntu

https://www.mongodb.com/docs/mongodb-shell/install/
https://www.mongodb.com/docs/mongodb-shell/run-commands/

```sh
lsb_release -a
openssl --version
```

```sh
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo tee /etc/apt/trusted.gpg.d/server-7.0.asc
sudo apt-get update
sudo apt-get install -y mongodb-mongosh-shared-openssl3
mongosh --version
```

```sh
mongosh mongodb://docadmin:password@mydocumentdb-982383527471.us-east-1.docdb-elastic.amazonaws.com:27017?retryWrites=false -tls
```
44 changes: 44 additions & 0 deletions documentdb/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'mongo'
require 'pry'

def insert_one collection
doc = {
name: 'Steve',
hobbies: [ 'hiking', 'tennis', 'fly fishing' ],
siblings: {
brothers: 0,
sisters: 1
}
}
result = collection.insert_one(doc)
puts result.n
end

def insert_many collection
docs = [ { _id: 1, name: 'Steve',
hobbies: [ 'hiking', 'tennis', 'fly fishing' ],
siblings: { brothers: 0, sisters: 1 } },
{ _id: 2, name: 'Sally',
hobbies: ['skiing', 'stamp collecting' ],
siblings: { brothers: 1, sisters: 0 } } ]
result = collection.insert_many(docs)
puts result.inserted_count
end

def query collection
collection = client[:people]
collection.find.each do |document|
puts document.inspect
end
end


client = Mongo::Client.new(
['mydocumentdb-982383527471.us-east-1.docdb-elastic.amazonaws.com:27017'],
database:'test',
ssl: true
)
#client = Mongo::Client.new('mongodb://docadmin:password@mydocumentdb-982383527471.us-east-1.docdb-elastic.amazonaws.com:27017')
db = client.database
collection = client[:people]
binding.pry

0 comments on commit bd36d25

Please sign in to comment.