Darn, I was hoping to pay you back for all the electrical help and advice!
Okay, here's a new question where experts might be able to help. TeslaMS stores Tesla's streaming records like this:
{ "_id" : ObjectId("5664a620b4edb81004982776"), "ts" : 1449436711414, "record" : [ "1449436711414", "18", "66402.0", "86", "140", "92", "38.00", "-89.00", "-10", "D", "224", "204", "90" ] }
record is [ timestamp, speed, odometer, soc, elevation, est_heading, latitude, longitude, power, shift_state, range, est_range, heading ]
With "record" being a comma-separated list without labels, is there a way for me to use standard "find" commands (or any other commands) to search for records based on elements of the "record" list? For example, if I wanted to pull all records where the power list field is greater than 200, is there an easy way to do this without doing an export and re-import to a more structured document?
Thanks!
db.tesla.find( { "record.8" : { $gt : "200" } } )
> db.tesla_stream.count({ "record.8": { $regex: /^-1..$/, $gte: "-123" } })
8
> db.tesla_stream.count({ "record.8": { $regex: /^-1..$/, $gte: "-124" } })
0
Close, but the problem with the comparison here is that it's a string comparison, so this will also match "21".
I was afraid of that, and bad me only tested with a couple of test cases that went well (where the string compare did the right thing)... No QA job for me!
However, have you tried http://stackoverflow.com/questions/3521601/is-it-possible-to-cast-in-a-mongodb-query ? It seems like it would do the right thing...
Something like: db.tesla.find('record.8 > 200') ?
db.tesla_stream.find('this.record[8] > 200')
db.tesla_stream.find('this.record[8] > 400');
[NOPARSE]
112:~>time mongo tesla --eval 'db.tesla_stream.find({ "record.8": { $regex: /^[4-9]..$/, $gte: "400" } }).forEach(printjson)'
MongoDB shell version: 3.0.7
connecting to: tesla
0.048u 0.011s 0:16.40 0.3% 0+0k 880+0io 6pf+0w
[/NOPARSE]
[NOPARSE]
113:~>time mongo tesla --eval 'db.tesla_stream.find("this.record[8] > 400").forEach(printjson)'
MongoDB shell version: 3.0.7
connecting to: tesla
0.054u 0.004s 4:46.99 0.0% 0+0k 992+0io 6pf+0w
[/NOPARSE]
So for 10.6M records, 16.4 seconds vs. 4 minutes, 47 seconds.
$regex it is.![]()
Cool. As a sanity check, you may want to ensure that the 2 queries return the same set of documents...
db.tesla_stream.find({ $or: [ { "record.8" : { $regex: /^[0-9]{1,2}$/ }} , { "record.8" : { $regex: /^-/ } } , { "record.8" : { $regex: /^[0-9]..$/ , $lte: "230" } } ] } )