PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Friday the 13th of December, 2019

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[11:01:35] <robertparkerx> How could I search for number and name for the same $_GET
[11:01:36] <robertparkerx> $api_mongo->find('customer', array('number' => new MongoDB\BSON\Regex( '^'.$_GET['searchCustomer'].'', 'i' )), null);
[11:02:48] <robertparkerx> not number AND number OR name
[11:03:03] <robertparkerx> I mean number AND name but number OR name
[11:03:11] <robertparkerx> :|
[11:03:23] <robertparkerx> I mean number OR name
[11:04:41] <robertparkerx> I see this https://docs.mongodb.com/manual/reference/operator/query/or/
[11:04:47] <robertparkerx> but I'm using the mongo php library
[11:08:58] <robertparkerx> Would it be
[11:09:02] <robertparkerx> $response = $api_mongo->find('customer', array( '$or' => array( 'number' => new MongoDB\BSON\Regex( '^'.$_GET['searchCustomer'].'', 'i' ) ), array( 'name' => new MongoDB\BSON\Regex( '^'.$_GET['searchCustomer'].'', 'i' ) ) ), null);
[11:15:04] <robertparkerx> it said it must be an array but I thought it was
[11:15:20] <robertparkerx> I think I have to remove 'customer' but where do I use it?
[11:53:50] <robertparkerx> Okay I got everything except for regex working
[11:53:54] <robertparkerx> $response = $api_mongo->find('customer', array( '$or' => array( array('number' => new MongoDB\BSON\Regex( '^'.$_GET['searchCustomer'].'', 'i' )), array( 'name' => new MongoDB\BSON\Regex( '^'.$_GET['searchCustomer'].'', 'i' )) )), null);
[13:13:52] <GothAlice> robertparkerx: The driver in use would have no impact on the server-side interpretation of a query. (Though I'll admit, PHP does almost suck that badly. Ref: parse_str, automatic integer interpretation and comparison between numeric string prefixes, …)
[13:14:37] <robertparkerx> Okay
[13:15:00] <GothAlice> Likely due to PHP's weird use of "array" to mean everything, but that isn't the type of array $or (or $and for that matter) expect. Not an associative array. Use a bare one. $or of multiple choices, $and of multiple choices, defined as an array of associative arrays of those choices.
[13:15:17] <GothAlice> In easier to read syntax: {$or: [{name: "Alice"}, {age: 27}]}
[13:16:23] <GothAlice> Or that could just be the bizzaire word wrapping I'm dealing with with such a verbose block of code. ¬_¬
[13:17:25] <GothAlice> Yup, that's word wrapping and my eyes naturally sliding over word pattern repetitions, apologies. Ugh. →find. Not… find_one v. find_many? How old is your driver?
[13:17:28] <robertparkerx> Hahaha
[13:17:38] <robertparkerx> It should be new
[13:17:48] <robertparkerx> I just upgraded it a few months ago
[13:18:39] <GothAlice> Ah, okay, PHP didn't do the find_one/find_many split, they did the find (which means many) v. findOne.
[13:18:40] <robertparkerx> I'm using an old api and I converted to the new one
[13:18:46] <robertparkerx> That's why it' susing find
[13:19:06] <robertparkerx> That's probably the confusion
[13:19:34] <robertparkerx> I didn't change any of the codebase but the api
[13:21:00] <GothAlice> Yup, I badly enough can't parse that (even MUSHcode is easier for my eyes… ;) that I can't see a problem. There are some superfluous .'' concatenations, but those shouldn't matter.
[13:29:53] <robertparkerx> Ah yea lol
[13:29:59] <robertparkerx> I'm the person who has that bad habit
[13:30:00] <robertparkerx> :(