2

is there any way I can pass a MongoDB query like db.things.find() directly to the Mongo C Driver or the Javascript driver node-mongo-native to make a query?

I am wondering the native driver is able to evaluate the query and return the result.

How to do that?

Thanks!

zs2020
  • 53,766
  • 29
  • 154
  • 219

1 Answers1

3

The method mongo_simple_str_command(…) in mongo.h seems to be what you are searching for.

mongo_simple_str_command(conn, db, "$eval", "db.foo.find()", out);

I found an usage example here: https://github.com/mongodb/mongo-c-driver/blob/master/test/platform/linux/timeouts.c

nutlike
  • 4,835
  • 1
  • 25
  • 33
  • Thanks for the info. I see *mongo_run_command* in the mongo.h, I will try it later today. – zs2020 Feb 22 '13 at 18:04
  • @sza: Would you mind sharing the results of your try? Since I never used this I am curious if it worked out. – nutlike Mar 09 '13 at 09:39
  • 1
    Technically this works but the find() actually returns a iterator, to make it fully work, i have to append a javascript function something like .forEach(function(x){printjson(x);}). – zs2020 Mar 09 '13 at 17:16