How to add self-signed certificates to replica set nodes?
https://medium.com/@rossbulat/deploy-a-3-node-mongodb-3-6-replica-set-with-x-509-authentication-self-signed-certificates-d539fda94db4
#mongo #mongodb #ssl #self_signed #openssl
https://medium.com/@rossbulat/deploy-a-3-node-mongodb-3-6-replica-set-with-x-509-authentication-self-signed-certificates-d539fda94db4
#mongo #mongodb #ssl #self_signed #openssl
Medium
Deploy a 3-Node MongoDB 4.0 Replica Set with X.509 Authentication + Self Signed Certificates
This article will guide you through the process of setting up a MongoDB cluster that will utilise X.509 authentication with self signed…
In order to see how much time your mongoDB slave is behind the primary node:
#mongodb #mongo #slave #printSlaveReplicationInfo #replica #replication
rs0:SECONDARY> db.printSlaveReplicationInfo()
source: mongo.mongo.com:27017
syncedTo: Mon Nov 12 2018 06:33:40 GMT+0000 (UTC)
-4 secs (0 hrs) behind the primary
#mongodb #mongo #slave #printSlaveReplicationInfo #replica #replication
How to check
We assume here that you have a replica set in place. First download the python script for our nagios plugin:
Now the
Create a new file
Create a new file in
This service gets enabled where it finds
#sysadmin #icinga2 #mongodb #replication #replication_lag #nagios_plugin
MongoDB
replication lag in Icinga2
and get notified when it is over 15 seconds?We assume here that you have a replica set in place. First download the python script for our nagios plugin:
cd /usr/lib/nagios/plugins
git clone git://github.com/mzupan/nagios-plugin-mongodb.git
Now the
Icinga2
part. You first need to create a command for replication lag check:cd /etc/icinga2/conf.d/commands
Create a new file
replication_lag.conf
:object CheckCommand "check_replication_lag" {
import "plugin-check-command"
command = [ PluginDir + "/nagios-plugin-mongodb/check_mongodb.py", "-A", "replication_lag" ]
arguments = {
"-H" = "$mongo_host$"
"-P" = "$mongo_port$"
}
}
Create a new file in
services
folder called replication_lag.conf
:apply Service for (display_name => config in host.vars.replication) {
import "generic-service"
check_command = "check_replication_lag"
vars += config
assign where host.vars.replication
}
This service gets enabled where it finds
replication
in host config. Now in secondary mongoDB hosts configuration add the below part:vars.replication["Secondary DB"] = {
mongo_host = "slave.example.com"
mongo_port = 27017
}
#sysadmin #icinga2 #mongodb #replication #replication_lag #nagios_plugin
MongoDB server Load Average: 0.5 (It can reach 16)
Database Size: 100GB (It is compressed in MySQL it reaches 300 GB in size!)
Req/Sec: 500
Our server seems hungry for more requests and more data.
#mongodb #mongo #awesomeness
Database Size: 100GB (It is compressed in MySQL it reaches 300 GB in size!)
Req/Sec: 500
Our server seems hungry for more requests and more data.
#mongodb #mongo #awesomeness
In
It will find all users that their names start with
#mongoDB #pymongo #regex
MongoDB
you can use $regex
in order to find something based on a regex pattern:my_col.find({'name': { $regex: '^ali.*' } })
It will find all users that their names start with
ali
. Now let's say you want to search users based on their phone country code which has a + in its number like +98901...
. You need to escape the + character but escape it twice:my_col.find({'phone': { $regex: '^\\+98.*' } })
#mongoDB #pymongo #regex
Is there a way to create ObjectID from an INT in
#mongodb #objectid #pymongo #python #bson #int
MongoDB
?import bson
def object_id_from_int(n):
s = str(n)
s = '0' * (24 - len(s)) + s
return bson.ObjectId(s)
def int_from_object_id(obj):
return int(str(obj))
n = 12345
obj = object_id_from_int(n)
n = int_from_object_id(obj)
print(repr(obj)) # ObjectId('000000000000000000012345')
print(n) # 12345
#mongodb #objectid #pymongo #python #bson #int
Did you know you can use jsonSchema in MongoDB to search for documents?
Let's say you have
Now let's say you want to find all documents that has a customer_id of type
In Mongo shell:
This schema says look for documents that have
Interesting, right? :)
#database #mongodb #jsonSchema #json_schema
Let's say you have
users
collection with data below:{ "_id" : ObjectId("5f64bd1eca8806f2c04fcbe3"), "customer_id" : 100, "username" : "john" }
{ "_id" : ObjectId("5f64bd1eca8806f2c04fcbe5"), "customer_id" : 206, "username" : "new_customer" }
{ "_id" : ObjectId("60420df441558d6671cf54f2"), "customer_id" : "123", "username" : "Ali" }
Now let's say you want to find all documents that has a customer_id of type
string
instead of int
.In Mongo shell:
let ms = {required: ["customer_id"], properties: {customer_id: {bsonType: "string"}}}
This schema says look for documents that have
customer_id
field with string
type. To search:> db.customers.find({$jsonSchema: ms})
{ "_id" : ObjectId("60420df441558d6671cf54f2"), "customer_id" : "123", "username" : "Ali" }
Interesting, right? :)
#database #mongodb #jsonSchema #json_schema