Details
-
Question
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
None
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)
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