Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I executed a command in mongo.exe

> db.tablebusiness.find({"_id": "the-simmons-paradise__41.85_-87.88"});

I got results:

Now I try similar command in rockmongo. If I execute

db.tablebusiness.find(
    {"_id": "the-simmons-paradise__41.85_-87.88"}
    );

Result:

{
   "retval": null,
   "ok": 1
} 

Basically it seems to tell me that the result is ok or something like that? I am not sure.

If I elaborate:

var cur = db.tablebusiness.find(
{"_id": "the-simmons-paradise__41.85_-87.88"}
);
cur.forEach(function(x){print(tojson(x))});

Result:

{
   "retval": null,
   "ok": 1
} 

Same problem.

If I do:

function () {
   return db.tablebusiness.find({"_id": "the-simmons-paradise__41.85_-87.88"});
}

What does it mean by hello.tablebusiness -> undefined is beyond me. As you see from above, I successfully execute the query just fine in mongo.exe

Looks like rockmongo has very limited feature. I wonder how to actually see result. How to execute random mongodb command in rockmongo and observe the result.

share|improve this question
    
Looks like it can't find the actual data you're looking for. Have you verified that it exists in the MongoDB database? –  Phil Aug 16 '12 at 8:37
    
yes. I actually want something more flexible than their query feature. –  Jim Thio Aug 16 '12 at 10:41
    
You mean retval: null means there is no result returned? I will try db.tablebusiness.find() then. –  Jim Thio Aug 16 '12 at 10:45
    
okay updated. The same query run fine on mongo.exe –  Jim Thio Aug 19 '12 at 18:37
    
I'll try asking in stackoverflow then. –  Jim Thio Aug 23 '12 at 2:22

2 Answers 2

To iterate through and list out all of the items returned by the cursor from find(), I used something like this:

function () {
  var cur = db.tablebusiness.find({
    "_id": "the-simmons-paradise__41.85_-87.88"
  });
  var result = [];
  cur.forEach(function(item) {
    result.push(item);
  });
  return result;
}

Since you need to actually return the value in order to view it in rockmongo I just append each result to an array and return the array. This may be why the print(tojson(x)) code you used in your loop does not give the desired result.

You can also try using the aggregation method, and just pipeline a single $match query, like so:

function () {
  return db.tablebusiness.aggregate([
    { $match: {
      "_id": "the-simmons-paradise__41.85_-87.88"
    }}
  ]);
}
share|improve this answer

The find() method returns a cursor object. In order to view the first returned record in the cursor you must call the next() method.

function () {
  return db.tablebusiness.find({
    "_id": "the-simmons-paradise__41.85_-87.88"
  }).next();
}
share|improve this answer
    
Consider expanding this answer to more than just one line of code. Brevity is acceptable, but fuller explanations are better. –  Paul White Nov 28 '12 at 2:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.