PHP code example of nddcoder / sql-to-mongodb-query
1. Go to this page and download the library: Download nddcoder/sql-to-mongodb-query library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nddcoder / sql-to-mongodb-query example snippets
$parser = new Nddcoder\SqlToMongodbQuery\SqlToMongodbQuery();
$query = $parser->parse("
SELECT id, username, email, created_at
FROM users
USE INDEX active_1_created_at_1
WHERE active = true and created_at >= date('2021-01-01')
ORDER BY created_at desc
LIMIT 10, 20
");
/*
Nddcoder\SqlToMongodbQuery\Model\FindQuery {#473
+filter: array:2 [
"active" => true
"created_at" => array:1 [
"$gte" => MongoDB\BSON\UTCDateTime {#926
+"milliseconds": "1609459200000"
}
]
]
+projection: array:4 [
"id" => 1
"username" => 1
"email" => 1
"created_at" => 1
]
+sort: array:1 [
"created_at" => -1
]
+limit: 20
+skip: 10
+collection: "users"
+hint: "active_1_created_at_1"
}
*/