Documentation
¶
Overview ¶
Package search provides primitives for searching Ops Manager related collections.
Index ¶
- func Members(a []opsmngr.Member, f func(opsmngr.Member) bool) (int, bool)
- func MongoDBIndexes(a []*opsmngr.IndexConfig, f func(configs *opsmngr.IndexConfig) bool) (int, bool)
- func MongoDBUsers(a []*opsmngr.MongoDBUser, f func(*opsmngr.MongoDBUser) bool) (int, bool)
- func Processes(a []*opsmngr.Process, f func(*opsmngr.Process) bool) (int, bool)
- func ReplicaSets(a []*opsmngr.ReplicaSet, f func(*opsmngr.ReplicaSet) bool) (int, bool)
- func ShardingConfig(a []*opsmngr.ShardingConfig, f func(*opsmngr.ShardingConfig) bool) (int, bool)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Members ¶
Members return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, Members returns n and false.
Example ¶
This example demonstrates searching a list of members by host.
package main
import (
"fmt"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
)
const rsName = "myReplicaSet_1"
var slaveDelay = float64(0)
var fixture = &opsmngr.AutomationConfig{
Auth: opsmngr.Auth{
AutoAuthMechanism: "MONGODB-CR",
Disabled: true,
AuthoritativeSet: false,
UsersWanted: []*opsmngr.MongoDBUser{
{
Mechanisms: &[]string{"SCRAM-SHA-1"},
Roles: []*opsmngr.Role{
{
Role: "test",
Database: "test",
},
},
Username: "test",
Database: "test",
},
},
},
Processes: []*opsmngr.Process{
{
Name: rsName,
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27000,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs1",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs1/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_2",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host1",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27010,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs2",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs2/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_3",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27020,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs3",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs3/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
},
ReplicaSets: []*opsmngr.ReplicaSet{
{
ID: "myReplicaSet",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ID: 0,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: rsName,
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 1,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_2",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 2,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_3",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
},
IndexConfigs: []*opsmngr.IndexConfig{
{
DBName: "test",
CollectionName: "test",
RSName: rsName,
Key: [][]string{
{"test", "1"},
},
Options: nil,
Collation: nil,
},
},
Version: 1,
}
func main() {
a := fixture.ReplicaSets[0].Members
const x = "myReplicaSet_2"
i, found := search.Members(a, func(m opsmngr.Member) bool { return m.Host == x })
if i < len(a) && found {
fmt.Printf("found %v at index %d\n", x, i)
} else {
fmt.Printf("%s not found\n", x)
}
}
Output: found myReplicaSet_2 at index 1
func MongoDBIndexes ¶
func MongoDBIndexes(a []*opsmngr.IndexConfig, f func(configs *opsmngr.IndexConfig) bool) (int, bool)
MongoDBIndexes return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, MongoDBIndexes returns n and false.
Example ¶
This example demonstrates searching an index by RSName.
package main
import (
"fmt"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
)
const rsName = "myReplicaSet_1"
var slaveDelay = float64(0)
var fixture = &opsmngr.AutomationConfig{
Auth: opsmngr.Auth{
AutoAuthMechanism: "MONGODB-CR",
Disabled: true,
AuthoritativeSet: false,
UsersWanted: []*opsmngr.MongoDBUser{
{
Mechanisms: &[]string{"SCRAM-SHA-1"},
Roles: []*opsmngr.Role{
{
Role: "test",
Database: "test",
},
},
Username: "test",
Database: "test",
},
},
},
Processes: []*opsmngr.Process{
{
Name: rsName,
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27000,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs1",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs1/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_2",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host1",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27010,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs2",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs2/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_3",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27020,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs3",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs3/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
},
ReplicaSets: []*opsmngr.ReplicaSet{
{
ID: "myReplicaSet",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ID: 0,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: rsName,
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 1,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_2",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 2,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_3",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
},
IndexConfigs: []*opsmngr.IndexConfig{
{
DBName: "test",
CollectionName: "test",
RSName: rsName,
Key: [][]string{
{"test", "1"},
},
Options: nil,
Collation: nil,
},
},
Version: 1,
}
func main() {
a := fixture
const x = "myReplicaSet_1"
i, found := search.MongoDBIndexes(a.IndexConfigs, func(r *opsmngr.IndexConfig) bool {
return r.RSName == x
})
if i < len(a.IndexConfigs) && found {
fmt.Printf("found %v at index %d\n", x, i)
} else {
fmt.Printf("%s not found\n", x)
}
}
Output: found myReplicaSet_1 at index 0
func MongoDBUsers ¶
func MongoDBUsers(a []*opsmngr.MongoDBUser, f func(*opsmngr.MongoDBUser) bool) (int, bool)
MongoDBUsers return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, MongoDBUsers returns n and false.
Example ¶
This example demonstrates searching a list of db users by username.
package main
import (
"fmt"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
)
const rsName = "myReplicaSet_1"
var slaveDelay = float64(0)
var fixture = &opsmngr.AutomationConfig{
Auth: opsmngr.Auth{
AutoAuthMechanism: "MONGODB-CR",
Disabled: true,
AuthoritativeSet: false,
UsersWanted: []*opsmngr.MongoDBUser{
{
Mechanisms: &[]string{"SCRAM-SHA-1"},
Roles: []*opsmngr.Role{
{
Role: "test",
Database: "test",
},
},
Username: "test",
Database: "test",
},
},
},
Processes: []*opsmngr.Process{
{
Name: rsName,
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27000,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs1",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs1/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_2",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host1",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27010,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs2",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs2/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_3",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27020,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs3",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs3/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
},
ReplicaSets: []*opsmngr.ReplicaSet{
{
ID: "myReplicaSet",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ID: 0,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: rsName,
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 1,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_2",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 2,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_3",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
},
IndexConfigs: []*opsmngr.IndexConfig{
{
DBName: "test",
CollectionName: "test",
RSName: rsName,
Key: [][]string{
{"test", "1"},
},
Options: nil,
Collation: nil,
},
},
Version: 1,
}
func main() {
a := fixture.Auth.UsersWanted
const x = "test"
i, found := search.MongoDBUsers(a, func(m *opsmngr.MongoDBUser) bool { return m.Username == x })
if i < len(a) && found {
fmt.Printf("found %v at index %d\n", x, i)
} else {
fmt.Printf("%s not found\n", x)
}
}
Output: found test at index 0
func Processes ¶
Processes return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, Processes returns n and false.
Example ¶
This example demonstrates searching a list of processes by name.
package main
import (
"fmt"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
)
const rsName = "myReplicaSet_1"
var slaveDelay = float64(0)
var fixture = &opsmngr.AutomationConfig{
Auth: opsmngr.Auth{
AutoAuthMechanism: "MONGODB-CR",
Disabled: true,
AuthoritativeSet: false,
UsersWanted: []*opsmngr.MongoDBUser{
{
Mechanisms: &[]string{"SCRAM-SHA-1"},
Roles: []*opsmngr.Role{
{
Role: "test",
Database: "test",
},
},
Username: "test",
Database: "test",
},
},
},
Processes: []*opsmngr.Process{
{
Name: rsName,
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27000,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs1",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs1/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_2",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host1",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27010,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs2",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs2/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_3",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27020,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs3",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs3/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
},
ReplicaSets: []*opsmngr.ReplicaSet{
{
ID: "myReplicaSet",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ID: 0,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: rsName,
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 1,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_2",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 2,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_3",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
},
IndexConfigs: []*opsmngr.IndexConfig{
{
DBName: "test",
CollectionName: "test",
RSName: rsName,
Key: [][]string{
{"test", "1"},
},
Options: nil,
Collation: nil,
},
},
Version: 1,
}
func main() {
a := fixture.Processes
const x = "myReplicaSet_2"
i, found := search.Processes(a, func(p *opsmngr.Process) bool { return p.Name == x })
if i < len(a) && found {
fmt.Printf("found %v at index %d\n", x, i)
} else {
fmt.Printf("%s not found\n", x)
}
}
Output: found myReplicaSet_2 at index 1
func ReplicaSets ¶
func ReplicaSets(a []*opsmngr.ReplicaSet, f func(*opsmngr.ReplicaSet) bool) (int, bool)
ReplicaSets return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, ReplicaSets returns n and false.
Example ¶
This example demonstrates searching a list of replica sets by ID.
package main
import (
"fmt"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
)
const rsName = "myReplicaSet_1"
var slaveDelay = float64(0)
var fixture = &opsmngr.AutomationConfig{
Auth: opsmngr.Auth{
AutoAuthMechanism: "MONGODB-CR",
Disabled: true,
AuthoritativeSet: false,
UsersWanted: []*opsmngr.MongoDBUser{
{
Mechanisms: &[]string{"SCRAM-SHA-1"},
Roles: []*opsmngr.Role{
{
Role: "test",
Database: "test",
},
},
Username: "test",
Database: "test",
},
},
},
Processes: []*opsmngr.Process{
{
Name: rsName,
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27000,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs1",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs1/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_2",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host1",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27010,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs2",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs2/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
{
Name: "myReplicaSet_3",
ProcessType: "mongod",
Version: "4.2.2",
AuthSchemaVersion: 5,
FeatureCompatibilityVersion: "4.2",
Disabled: false,
ManualMode: false,
Hostname: "host0",
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: 27020,
},
Storage: &opsmngr.Storage{
DBPath: "/data/rs3",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/rs3/mongodb.log",
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
},
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000.0,
TimeThresholdHrs: 24,
},
LastGoalVersionAchieved: 0,
Cluster: "",
},
},
ReplicaSets: []*opsmngr.ReplicaSet{
{
ID: "myReplicaSet",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ID: 0,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: rsName,
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 1,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_2",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
{
ID: 2,
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: "myReplicaSet_3",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
},
IndexConfigs: []*opsmngr.IndexConfig{
{
DBName: "test",
CollectionName: "test",
RSName: rsName,
Key: [][]string{
{"test", "1"},
},
Options: nil,
Collation: nil,
},
},
Version: 1,
}
func main() {
a := fixture.ReplicaSets
const x = "myReplicaSet"
i, found := search.ReplicaSets(a, func(r *opsmngr.ReplicaSet) bool { return r.ID == x })
if i < len(a) && found {
fmt.Printf("found %v at index %d\n", x, i)
} else {
fmt.Printf("%s not found\n", x)
}
}
Output: found myReplicaSet at index 0
func ShardingConfig ¶ added in v0.7.0
func ShardingConfig(a []*opsmngr.ShardingConfig, f func(*opsmngr.ShardingConfig) bool) (int, bool)
ShardingConfig return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, ShardingConfig returns n and false.
Example ¶
This example demonstrates searching a list of replica sets by ID.
package main
import (
"fmt"
"go.mongodb.org/ops-manager/opsmngr"
"go.mongodb.org/ops-manager/search"
)
func main() {
a := []*opsmngr.ShardingConfig{{Name: "myCluster"}}
const x = "myCluster"
i, found := search.ShardingConfig(a, func(r *opsmngr.ShardingConfig) bool { return r.Name == x })
if i < len(a) && found {
fmt.Printf("found %v at index %d\n", x, i)
} else {
fmt.Printf("%s not found\n", x)
}
}
Output: found myCluster at index 0
Types ¶
This section is empty.