diff --git a/documentdb/Gemfile b/documentdb/Gemfile new file mode 100644 index 0000000..2087eb6 --- /dev/null +++ b/documentdb/Gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" +gem 'ox' +gem 'mongo' +gem 'pry' \ No newline at end of file diff --git a/documentdb/Gemfile.lock b/documentdb/Gemfile.lock new file mode 100644 index 0000000..b181c2b --- /dev/null +++ b/documentdb/Gemfile.lock @@ -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 diff --git a/documentdb/Readme.md b/documentdb/Readme.md new file mode 100644 index 0000000..df5a3eb --- /dev/null +++ b/documentdb/Readme.md @@ -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 +``` \ No newline at end of file diff --git a/documentdb/main.rb b/documentdb/main.rb new file mode 100644 index 0000000..53e4c85 --- /dev/null +++ b/documentdb/main.rb @@ -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 \ No newline at end of file