My data retrieval process from mongodb involves obtaining the data and transferring it to the client side using the following approach:
error_reporting(E_ALL);
ini_set('display_errors', '1');
require '../vendor/autoload.php';
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->hotel->airlines;
$cursor = $collection->find();
echo json_encode(iterator_to_array($cursor));
This represents a portion of the retrieved data from the server:
[{
"_id": {
"$oid": "609c51803d59e5004f225a92"
},
"added_by": "609c35b4f940b04db90a7222",
"airline_category": "regional",
...
}]
On the client side, the variables holding the retrieved data appear as follows:
export default {
name: 'Seed_Airlines',
data() {
return {
airlineForm:{},
added_by:'',
allusersfetched:'',
airline_name:'',
...
fetchedid:'',
}
},
In the mounted section, I execute the following code:
axios.get(fetch_all_airlines)
.then(response => {
console.log(response.data);
var data = response.data;
this.data = data
})
.catch(e => {
this.errors.push(e)
});
As the returned data includes a hidden id field:
"_id": {
"$oid": "609c51803d59e5004f225a92"
},
I aim to remove the unnecessary parts "_id": {
along with the additional }
leaving only
"$oid": "609c51803d59e5004f225a92"
within the data object.
How can I directly utilize the entire retrieved data object to populate my forms since it aligns perfectly with the initial data structure used to insert entries into mongoDB?