querying data from rs.status()

854 views
Skip to first unread message

pm

unread,
Aug 16, 2011, 2:01:23 AM8/16/11
to mongodb-user
how to write a query against rs.status() to get details of a specific
member in a set. I'm trying this to do in DB Shell.

I can get details based on member array index

foo:PRIMARY> rs.status().members[0].optime.t
1312133994000

but how to write something like get me optime where name="MacBook-
Pro-2.local:27017"

below is my sample rs.status() output.

foo:PRIMARY> rs.status();
{
"set" : "foo",
"date" : ISODate("2011-08-16T05:52:51Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "MacBook-Pro-2.local:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1312133994000,
"i" : 1
},
"optimeDate" : ISODate("2011-07-31T17:39:54Z"),
"self" : true
},
{
"_id" : 1,
"name" : "MacBook-Pro-2.local:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1389,
"optime" : {
"t" : 1312133994000,
"i" : 1
},
"optimeDate" : ISODate("2011-07-31T17:39:54Z"),
"lastHeartbeat" : ISODate("2011-08-16T05:52:50Z")
},
{
"_id" : 2,
"name" : "MacBook-Pro-2.local:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1389,
"optime" : {
"t" : 1312133994000,
"i" : 1
},
"optimeDate" : ISODate("2011-07-31T17:39:54Z"),
"lastHeartbeat" : ISODate("2011-08-16T05:52:50Z")
}
],
"ok" : 1
}

Scott Hernandez

unread,
Aug 16, 2011, 2:06:52 AM8/16/11
to mongod...@googlegroups.com
Something like this in a for loop:

for(var m in rs.status().members) { if(m.name ==
"MacBook-Pro-2.local:27017") { print(m.optime} }}


You can write any javascript you want, including functions or loops.
If you want to do this from another langauge/driver you can look at
how rs.status() is written by removing the "()" from the end.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages