Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Gone away
-
2.0.4, 2.6.4, 2.7.6
-
None
-
Linux (Debian). N/A, really.
-
Query
Description
The DB profiler creates illegal documents. These documents contain:
1) keys with $ in the name
2) keys with . in the name
This problem makes working with these documents incredibly difficult.
Here's an example:
PRIMARY> test.record = db.system.profile.findOne({"ts" : ISODate("2012-08-12T14:26:18.806Z")})
|
{
|
"ts" : ISODate("2012-08-12T14:26:18.806Z"),
|
"op" : "query",
|
"ns" : "gimmebar.collectionassets",
|
"query" : {
|
"$query" : {
|
"collection_id" : "redacted"
|
},
|
"$orderby" : {
|
"date" : -1
|
}
|
},
|
"ntoreturn" : 5,
|
"nscanned" : 169,
|
"scanAndOrder" : true,
|
"nreturned" : 5,
|
"responseLength" : 325,
|
"millis" : 227,
|
"client" : "redacted",
|
"user" : ""
|
}
|
|
PRIMARY> db.tmp_profiler_test.insert(testrecord)
|
Tue Aug 14 18:39:40 uncaught exception: field names cannot start with $ [$query]
|
The same thing happens for $orderby, $or, $set, etc., as well as for keys with "." in the name.
I think the profiler should not create documents that can't be inserted. (I had to insert them into another collection because I wanted to filter the profiler data set, but I can't delete from a capped collection, which db.system.profile is.)
I realize this changes the data format of the profiler, but it seems like the right move to me.
—
As a workaround, for those developers who might stumble upon this, I managed to get the following transposition to work, but it's far from ideal:
// recursion is fun
|
function rename$(r) {
|
for (k in r) {
|
var changed = false;
|
var newk = k;
|
if (newk.indexOf(".") != -1) {
|
changed = true;
|
newk = newk.replace(".", "_DOT_", "g");
|
}
|
if (newk.indexOf("$") != -1) {
|
changed = true;
|
newk = newk.replace("$", "_DOLLAR_", "g");
|
}
|
if (changed) {
|
r[newk] = r[k];
|
delete r[k];
|
}
|
if (typeof r[newk] == "object") {
|
r[newk] = rename$(r[newk]);
|
}
|
}
|
return r;
|
}
|
db.tmp_profiler_test.drop();
|
db.system.profile.find(query_parameters).forEach(function(r) { r = rename$(r); db.tmp_profiler_test.insert(r);})
|
(I also couldn't get this box to respect wiki markup, so editor: feel free to fix.) [Done.]
Attachments
Issue Links
- is duplicated by
-
SERVER-7349 Queries with dotted notation create invalid dotted keys in system.profile
-
- Closed
-
- is related to
-
SERVER-13245 system.profile query format inconsistent
-
- Backlog
-
-
SERVER-30575 Please add escaping convention for dot and dollar signs!
-
- Backlog
-
-
SERVER-6767 Interpret $query as special so you can copy profiler/logged queries into shell
-
- Closed
-