powershell and mongodrivers

113 views
Skip to first unread message

tony...@nwea.org

unread,
May 24, 2016, 5:21:41 PM5/24/16
to mongodb-user
ok i've been using the cli driven via powershell but that just generates an extra layer of junk to deal with (things like json.stringify etc), I'd like to use the mongo drivers.  I'm able to do things like queries etc within powershell but I need to also monitor the mongo depoyment.   I have not found an example on the internet yet that works they all use getserver() but that function apparently doesn't exist in the newest drivers.  I just want to get the results in powershell of a db.serverstatus.  
Any Ideas?
Thanks 

tr

Craig Wilson

unread,
May 25, 2016, 8:33:03 AM5/25/16
to mongodb-user
Hi Tony.

You just need to run the command explicitly.

var result = db.RunCommand<BsonDocument>("{serverStatus: 1}");

Whatever you need to do to translate that to powershell.

Craig

Vin

unread,
Feb 1, 2017, 7:00:31 AM2/1/17
to mongodb-user
Hi,
I'm hijacking that question because I try to understand a bit more and cannot find an answer online :
from the Mongo shell I can do 
db.runCommand({serverStatus : 1})
which can be done with cmongocxx as
db.RunCommand<BsonDocument>("{serverStatus: 1}");

But in the mongo shell (if I understood correctly) there is a db.serverStatus() command which is an alias of db.runCommand({serverStatus : 1}).
So, what I'm trying to do is to have the same result with mongocxx as I have with this mongo shell command db.serverStatus().ok
any idea ?

second question, when we do db.serverStatus().ok from the mongo shell, is the "filtering" job of the .ok to the db.serverStatus() document done by the mongo shell or by the mongo server ?

Thanks for the help.
Vincent.

The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

Andrew Morrow

unread,
Feb 2, 2017, 11:29:48 AM2/2/17
to mongod...@googlegroups.com

In general, please do not re-open old threads, especially if they are only tangentially related to your question.

If I understand correctly, you want to know two things:

- How to issue a serverStatus command with the mongocxx driver.
- Whether the .ok part of the shell expression db.serverStatus().ok is evaluated at the server, or in the shell.

For the first question, I recommend looking at the 'connect' example for the C++ driver, which shows how to run the isMaster command. It should be easy to replace the command name with serverStatus. You can obtain the value of the ok field from the command result with result['ok'], using the variable names as they are in the example.

For the second question, the extraction of the 'ok' field is done client side (i.e. in the shell).

Thanks,
Andrew



--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d17a3732-f1c4-487e-83f6-56436c2da163%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Vin

unread,
Feb 3, 2017, 8:58:53 AM2/3/17
to mongodb-user
Perfect,
thank you for the answer.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.

To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages