[SERVER-5992] system.indexes.find() from .js file doesn't work for me. Created: 01/Jun/12  Updated: 15/Aug/12  Resolved: 01/Jun/12

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Peter Burkholder Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Can you tell me why the following query.js doesn't work? I would like to script our ability to list the indexes on a db.

rs.slaveOk();
printjson(db.getCollectionNames()); # this command works as expected
printjson(db.system.indexes.find()); # this command doesn't list the indexes. See below

The db.system.index.find() command works great from the interactive shell. But what I get when using:

mongo -u careverge -p secret careverge ./query.js

is

MongoDB shell version: 2.0.1
connecting to: careverge
[
"Analytics",
"Campaign",
"EmailAnalytics",
[snip]
]
{
"_mongo" : connection to 127.0.0.1,
"_db" : careverge,
"_collection" : careverge.system.indexes,
"_ns" : "careverge.system.indexes",
"_query" : {

},
"_fields" : null,
"_limit" : 0,
"_skip" : 0,
"_batchSize" : 0,
"_options" : 0,
"_cursor" : null,
"_numReturned" : 0,
"_special" : false,
"help" : function () {
print("find() modifiers");
print("\t.sort(

{...}

)");
print("\t.limit( n )");
print("\t.skip( n )");
print("\t.count() - total # of objects matching query, ignores skip,limit");
print("\t.size() - total # of objects cursor would return, honors skip,limit");
print("\t.explain([verbose])");
print("\t.hint(...)");
print("\t.showDiskLoc() - adds a $diskLoc field to each returned object");
print("\nCursor methods");
print("\t.forEach( func )");
print("\t.map( func )");
print("\t.hasNext()");
print("\t.next()");
},
"clone" : function () {
var q = new DBQuery(this._mongo, this._db, this._collection, this._ns, this._query, this._fields, this._limit, this._skip, this._batchSize, this._options);
q._special = this._special;
return q;
},
"_ensureSpecial" : function () {
if (this._special)

{ return; }

var n =

{query:this._query}

;
this._query = n;
this._special = true;
},
[snip]
},
"toString" : function () {
return "DBQuery: " + this._ns + " -> " + tojson(this.query);
}
}


Peter Burkholder | Cloud Engineer | AudaxHealth
peter.burkholder@audaxhealth.com
M: +1-301-204-5767 | Skype: peter.burkholder-audax
3000 K Street NW, Suite 350 | Washington, DC 20007
@audaxhealth | @careverge |Visit us on Facebook - Audax Health | Careverge

  • For optimal efficiency, I check email at 2-hour intervals during the workday; during release weeks
  • I check more frequently. Please use IM or phone for urgent matters


 Comments   
Comment by Scott Hernandez (Inactive) [ 01/Jun/12 ]

Use toArray() as instead you get back the cursor object, not the results:

printjson(db.system.indexes.find().toArray()); 

Generated at Thu Feb 08 03:10:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.