mongodb - PHP - Iterable Object Issue -


I am working on a site in which our system administrator can choose whether our data is either mangodeb Or I can recover both from elastic search or not, but I want to setup a switch case which will select the correct document recovery system based on priority in the site administrator section. When the mongo returns a stdClass object, I can print each item using something like the following items through the object:

  foreach ($ item as $ item) {Print_r ($ item); }   

Then I then add the total number of items to $ items- & gt; I can get it back using counting (). However, when using the elasticsearch I am returning an item that I should go:

  foreach ($ item ['hit'] ['hit'] as $ item) {print_r ($ item); }   

The count can be recovered using $ item ['hit'] ['total']. If I remove the array of objects (let's call it "$ last rupee" and count it (let's call it $ count) return data from rediscovery, how can i convert it to a stud class object such as mango Returns so that I can straighten through the class to get the value of each item, as well as call the method count () to get the count back? I want to do that so that I can easily switch between two data items without handling a completely different function.

I result as a result of ElasticSearch result for many reasons (or vice versa). One is that even now it will feel that as soon as you both Keep them in the same form, in the future, more fields may be required / manipulated This can be a nightmare.

One solution is that you create a new class, call DocumentItem , and both MongoDB and < code> Elastic Search results in this category. In this way, a part of your code that is assembled again, returns to MongoDB and ElasticSearch both at the return value of DocumentItem Object, using your defined methods.

And you have MongoDB & amp; Elastic Search Back to this object If a new area has to be added in the future, in the future, you have to update conversion tasks accordingly. And if a new document server has been added, you only have to type the conversion function, because the DocumentItem class is already well-defined.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -