MongoDB: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
==Raspbian==
==Raspbian==
<syntaxhighlight lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
Raspbian
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
apt install mongodb
apt install mongodb
nano /etc/mongodb.conf
nano /etc/mongodb.conf
Line 12: Line 17:
systemctl status mongodb
systemctl status mongodb
</syntaxhighlight>
</syntaxhighlight>
|valign='top' style='width:50%'|
|}


==Debian==
==Debian==
{|
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
| valign="top" |
!scope='col' style='text-align:left' colspan='2'|
<syntaxhighlight lang="bash">
Debian
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
curl -fsSL https://pgp.mongodb.com/server-8.0.asc \
curl -fsSL https://pgp.mongodb.com/server-8.0.asc \
  | sudo tee /etc/apt/keyrings/mongodb-8.0.asc >/dev/null
  | sudo tee /etc/apt/keyrings/mongodb-8.0.asc >/dev/null
Line 27: Line 38:
</syntaxhighlight>
</syntaxhighlight>


| valign="top" |
|valign='top' style='width:50%'|
<syntaxhighlight lang="bash">
<syntaxhighlight style='margin:3px 0' lang='bash'>
curl -fsSL https://pgp.mongodb.com/server-7.0.asc \
curl -fsSL https://pgp.mongodb.com/server-7.0.asc \
  | sudo tee /etc/apt/keyrings/mongodb-7.0.asc >/dev/null
  | sudo tee /etc/apt/keyrings/mongodb-7.0.asc >/dev/null
Line 38: Line 49:
SRC
SRC
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| colspan="2" |
|valign='top'|
----
<syntaxhighlight style='margin:3px 0' lang='bash'>
|-
| colspan="2" valign="top" |
<syntaxhighlight lang="bash">
sudo apt update
sudo apt update
sudo apt search  mongodb-org
sudo apt search  mongodb-org
Line 55: Line 62:
</syntaxhighlight>
</syntaxhighlight>


|valign='top'|
|}
|}


==MacOS==
==MacOS==
<syntaxhighlight lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
MacOS
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
brew tap | grep mongodb
brew tap | grep mongodb
xcode-select --install
xcode-select --install
Line 85: Line 98:
brew services list
brew services list
</syntaxhighlight>
</syntaxhighlight>
|valign='top'|
|}


==Mongosh==
==Mongosh==
<syntaxhighlight lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left' colspan='2'|
Mongosh
|-
|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
mongosh
mongosh
: <<'END_COMMENT'
: <<'END_COMMENT'
Line 118: Line 139:
END_COMMENT
END_COMMENT
</syntaxhighlight>
</syntaxhighlight>
|valign='top' style='width:50%'|
|}


==Compass==
==Compass==
<syntaxhighlight lang="bash">
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
!scope='col' style='text-align:left'|
Compass
|-
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
sudo wget -c https://downloads.mongodb.com/compass/mongodb-compass_1.44.5_amd64.deb -P ${HOME}/Downloads
sudo wget -c https://downloads.mongodb.com/compass/mongodb-compass_1.44.5_amd64.deb -P ${HOME}/Downloads
sudo dpkg -i    ${HOME}/Downloads/mongodb-compass_1.44.5_amd64.deb
sudo dpkg -i    ${HOME}/Downloads/mongodb-compass_1.44.5_amd64.deb
Line 128: Line 157:
sudo apt install -f
sudo apt install -f
</syntaxhighlight>
</syntaxhighlight>
|}


==Knowledge==
==Knowledge==
{|
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
|valign="top"|
!scope='col' style='text-align:left' colspan='2'|
sudo apt remove --auto-remove mc
Knowledge
sudo apt purge  --auto-remove mc  
|-
sudo apt purge mc
|valign='top' style='width:50%'|
 
<syntaxhighlight style='margin:3px 0' lang='bash'>
|valign="top"|
sudo apt remove --auto-remove mc
apt list --installed|grep mongodb-compass
sudo apt purge  --auto-remove mc  
sudo apt remove mongodb-compass
sudo apt purge mc
mongosh --quiet
</syntaxhighlight>
 
|valign="top"|
use  admin
show databases
show collections


|valign='top' style='width:50%'|
<syntaxhighlight style='margin:3px 0' lang='bash'>
apt list --installed|grep mongodb-compass
sudo apt remove mongodb-compass
mongosh --quiet
</syntaxhighlight>
|-
|-
|colspan="3"|
|valign='top'|
----
<syntaxhighlight style='margin:3px 0' lang='bash'>
use  admin
show databases
show collections
</syntaxhighlight>
|valign='top'|
<syntaxhighlight style='margin:3px 0' lang='js'>
show users;
db.getUsers();
db.dropUser("chorke", {w: "majority", wtimeout: 5000});
</syntaxhighlight>
|-
|-
| valign="top" |
|valign='top'|
db.createUser({
<syntaxhighlight style='margin:3px 0' lang='js'>
  user: "chorke",
db.createUser({
  pwd:  "sadaqah!",
  user: "chorke",
  roles: [
  pwd:  "sadaqah!",
    { role: "readWrite", db: "Gateway" },
  roles: [
    { role: "readWrite", db: "Onboarding" },
    { role: "readWrite", db: "Gateway" },
    { role: "readWrite", db: "OnboardingForm" }
    { role: "readWrite", db: "Onboarding" },
  ]
    { role: "readWrite", db: "OnboardingForm" }
});
  ]
 
});
| valign="top" |
</syntaxhighlight>
show users;
db.getUsers();
db.dropUser("chorke", {w: "majority", wtimeout: 5000});
 
| valign="top" |


|valign='top'|
|}
|}


==References==
==References==
{|
{|class='wikitable mw-collapsible' style='width:100%;margin:3px 0'
| valign="top" |
!scope='col' style='text-align:left' colspan='3'|
References
|-
|valign='top' style='width:33%'|
* [https://www.mongodb.com/try/download/compass MongoDB » Download » Compass (GUI)]
* [https://www.mongodb.com/try/download/compass MongoDB » Download » Compass (GUI)]
* [https://hevodata.com/learn/mongodb-compass-ubuntu/ MongoDB » Compass » On Ubuntu]
* [https://hevodata.com/learn/mongodb-compass-ubuntu/ MongoDB » Compass » On Ubuntu]
Line 184: Line 224:
* [https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ MongoDB » On macOS]
* [https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ MongoDB » On macOS]


| valign="top" |
|valign='top' style='width:34%'|
* [https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/ MongoDB » Schema Design Best Practices]
* [https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/ MongoDB » Schema Design Best Practices]
* [https://www.mongodb.com/docs/manual/core/wiredtiger/ MongoDB » Storage Engine » WiredTiger]
* [https://www.mongodb.com/docs/manual/core/wiredtiger/ MongoDB » Storage Engine » WiredTiger]
Line 194: Line 234:
* [https://www.mongodb.com/docs/manual/release-notes/ MongoDB » Release Notes]
* [https://www.mongodb.com/docs/manual/release-notes/ MongoDB » Release Notes]


| valign="top" |
|valign='top' style='width:33%'|


|-
|-
| colspan="3" |
|valign='top'|
----
|-
| valign="top" |
* [[Homebrew]]
* [[Homebrew]]
* [[Base64]]
* [[Base64]]
Line 209: Line 246:
* [[Wrk]]
* [[Wrk]]


| valign="top" |
|valign='top'|
 
| valign="top" |


|valign='top'|
|}
|}

Revision as of 15:39, 16 January 2026

Raspbian

Raspbian

apt install mongodb
nano /etc/mongodb.conf
: <<'END_COMMENT'
bind_ip = 127.0.0.1,10.19.83.105
port = 27017
END_COMMENT

systemctl start mongodb
systemctl enable mongodb
systemctl status mongodb

Debian

Debian

curl -fsSL https://pgp.mongodb.com/server-8.0.asc \
 | sudo tee /etc/apt/keyrings/mongodb-8.0.asc >/dev/null

cat << SRC | sudo tee /etc/apt/sources.list.d/mongodb-8.0.list >/dev/null
deb [arch=$(dpkg --print-architecture)\
 signed-by=/etc/apt/keyrings/mongodb-8.0.asc]\
 https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse
SRC
curl -fsSL https://pgp.mongodb.com/server-7.0.asc \
 | sudo tee /etc/apt/keyrings/mongodb-7.0.asc >/dev/null

cat << SRC | sudo tee /etc/apt/sources.list.d/mongodb-7.0.list >/dev/null
deb [arch=$(dpkg --print-architecture)\
 signed-by=/etc/apt/keyrings/mongodb-7.0.asc]\
 https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse
SRC
sudo apt update
sudo apt search  mongodb-org
sudo apt install mongodb-org

ps --no-headers -o comm 1
sudo systemctl status mongod
sudo systemctl daemon-reload
mongosh

MacOS

MacOS

brew tap | grep mongodb
xcode-select --install
brew tap mongodb/brew
brew tap

brew services stop mongodb-community
brew uninstall mongodb-community
brew cleanup

rm -rf ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community*
rm -rf  /usr/local/var/mongodb*

brew install mongodb-community
brew services start mongodb-community
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

brew services stop mongodb-community
vim /usr/local/etc/mongod.conf
: <<'END_COMMENT'
net:
  bindIp: 127.0.0.1,10.19.83.110
END_COMMENT
brew services start mongodb-community
brew services list

Mongosh

Mongosh

mongosh
: <<'END_COMMENT'
test> show databases;
admin   40.00 KiB
config  12.00 KiB
local   72.00 KiB
test>  use local
switched to db local
local> show collections;
startup_log
local> db.stats();
{
  db: 'local',
  collections: 1,
  views: 0,
  objects: 2,
  avgObjSize: 2370,
  dataSize: 4740,
  storageSize: 36864,
  indexes: 1,
  indexSize: 36864,
  totalSize: 73728,
  scaleFactor: 1,
  fsUsedSize: 296942022656,
  fsTotalSize: 371537641472,
  ok: 1
}
local> 
END_COMMENT

Compass

Compass

sudo wget -c https://downloads.mongodb.com/compass/mongodb-compass_1.44.5_amd64.deb -P ${HOME}/Downloads
sudo dpkg -i     ${HOME}/Downloads/mongodb-compass_1.44.5_amd64.deb
sudo apt install ${HOME}/Downloads/mongodb-compass_1.44.5_amd64.deb
sudo rm  -rf     ${HOME}/Downloads/mongodb-compass_1.44.5_amd64.deb
sudo apt --fix-broken install
sudo apt install -f

Knowledge

Knowledge

sudo apt remove --auto-remove mc
sudo apt purge  --auto-remove mc 
sudo apt purge mc
apt list --installed|grep mongodb-compass
sudo apt remove mongodb-compass
mongosh --quiet
use  admin
show databases
show collections
show users;
db.getUsers();
db.dropUser("chorke", {w: "majority", wtimeout: 5000});
db.createUser({
  user: "chorke",
  pwd:  "sadaqah!",
  roles: [
    { role: "readWrite", db: "Gateway" },
    { role: "readWrite", db: "Onboarding" },
    { role: "readWrite", db: "OnboardingForm" }
  ]
});

References

References