Question

I have this query

var startVal = Math.random();
db.coll.find({r: {$gt: startVal}}).sort({r: 1}).limit(1);

What's tripping me up is the sort. Can anyone help me convert this query into a C++ query?

Thanks!

Was it helpful?

Solution

Should be:

QUERY("r" << BSON("$gt" << startVal ) ).sort("r" << 1)

or even more simple:

QUERY("r" << GT << startVal ).sort("r")

limit is expressed as part of the call to execute the query (3rd param)

auto_ptr<DBClientCursor> cursor = c.query("DB.coll", QueryHere, 1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top