2

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.

user4951
  • 1,355
  • 5
  • 20
  • 39

2 Answers2

1

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();
}
thaddeusmt
  • 113
  • 5
iwind
  • 166
  • 2
1

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"
    }}
  ]);
}
thaddeusmt
  • 113
  • 5