Last active
August 24, 2021 01:28
-
-
Save gabanox/2f7dd295ebb2d2a91a7a531ccc9ea3c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create repository file | |
echo -e "[mongodb-org-4.0] \nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/4.0/x86_64/\ngpgcheck=1 \nenabled=1 \ngpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc" | sudo tee /etc/yum.repos.d/mongodb-org-4.0.repo | |
Install Mongo Shell | |
sudo yum install -y mongodb-org-shell | |
Downloads the CA Certificate for Amazon DocumentDB | |
wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem | |
Insert a document | |
---------------------------------------------------------------------------- | |
db.posts.insertOne( | |
{ | |
"title" : "first post title", | |
"body" : "first post body" , | |
"category" : "uncategorized" | |
}) | |
---------------------------------------------------------------------------- | |
Query | |
---------------------------------------------------------------------------- | |
db.posts.find( | |
{ | |
"title" : "first post title" | |
} | |
) | |
---------------------------------------------------------------------------- | |
Insert Many | |
---------------------------------------------------------------------------- | |
db.posts.insertMany( | |
[ | |
{ _id : "post-1" , "title" : "first post title", "body" : "first post body", "author" : "author1"}, | |
{ _id : "post-2" , "title" : "second post title", "body" : "second post body" , "author" : "author2"} | |
]) | |
---------------------------------------------------------------------------- | |
Transaction | |
---------------------------------------------------------------------------- | |
var dbSession = db.getMongo().startSession(); | |
var dbSessionObject = dbSession.getDatabase('Blog').getCollection('posts'); | |
dbSession.startTransaction( | |
{ readConcern: {level: 'snapshot'}, | |
writeConcern: {w: 'majority'} }); | |
dbSessionObject.updateOne({"_id": "post-1"}, { $set : {author: "author1"}}); | |
dbSessionObject.updateOne({"_id": "post-2"}, { $set: {author: "author2"}}); | |
dbSession.commitTransaction() | |
dbSession.endSession() | |
---------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment