I have a table with data as below:
[
{
"payment_id": 1,
"provider_id": "ABC123 ",
"status": "pending",
"item_service": [
{
"code": "NY100",
"provider_type":"Medical_Center",
"description": "Initial Consultation - History, examination and treatment",
"rate": "20"
},
{
"code": "NY101",
"provider_type":"Medical_Center",
"description": "Brief Consultation - Selective review, examination and treatment",
"rate": "25"
},
{
"code": "NY102",
"provider_type":"Medical_Center",
"description": "Standard Consultation - History, examination and treatment",
"rate": "30"
}
]
}
]
and the Search index function
the returned results are:
Please give me your thought how to split data and display with the key name on each value in results. eg:
"code": "PY102",
"provider_type":"Medical_Center",
"description": "Standard Consultation - History, examination and treatment",
"rate": "30"
If your make your index like:
function (doc) {
if (doc.item_service){
for (var m in doc.item_service){
for (var n in doc.item_service[m]){
index(n, doc.item_service[m][n], {"store":true});
}
}
}
}
than your fields will be:
"fields": {
"rate": [
"30",
"25",
"20"
],
"description": [
"Standard Consultation - History, examination and treatment",
"Brief Consultation - Selective review, examination and treatment",
"Initial Consultation - History, examination and treatment"
],
"code": [
"NY102",
"NY101",
"NY100"
],
"provider_type": [
"Medical_Center",
"Medical_Center",
"Medical_Center"
]
}
Is this the result you intended to get?
Related
I am trying to create a template from postman by sending this object:
{
"name": "listado_productos",
"language": "es",
"category": "TRANSACTIONAL",
"components": [
{
"type" : "HEADER",
"format": "document",
"example": {
"header_handle": [
"https://drive.google.com/file/d/1CcTpDZL3p0ltMFhIKU9Vhz1LWG0bQFpN/view?usp=share_link"
]}
},
{
"type": "BODY",
"text": "Buenas tardes, acá le enviamos el nuevo listado de precios. Muchas gracias"
},
{
"type": "FOOTER",
"text": "ABS."
}
]
}
If I try an example from the official business-management-api guide, it also rejects it for non-compliance with terms and conditions.
"name": "promotional_message",
"language": "en_US",
"category": "TRANSACTIONAL",
"components": [{
"type":"BODY",
"text":"Hi {{1}}, get an extra 10% off every order above $300.",
"example":{"body_text":[["Sonia"]]}
},
{
"type":"HEADER",
"format":"TEXT",
"text": "Bonus Tuesday starts now!"
},
{
"type":"FOOTER",
"text":"Not interested? Tap Stop promotions"
},
{
"type":"BUTTONS",
"buttons":[{"type":"QUICK_REPLY", "text": "Shop now"},
{"type":"QUICK_REPLY", "text": "Stop promotions"}]
}]
The response is that it is rejected for being duplicate or not complying with WhatsApp Busiess Api terms and services but it is not true, I read the terms and conditions and the file / message format complies. Does anyone identify the problem?
I have my MongoDb documents like this:
{
... OTHER FIELDS ...
"Name": "3m india ltd.",
"BSECode": "523395",
"NSECode": "3MINDIA",
"News": {
"Bites": [
{
"href": "https://www.thehindubusinessline.com/companies/3m-india-develops-cleaning-solution-covid-relevant-signage-for-global-application/article34462888.ece",
"headline": "3M India develops cleaning solution, Covid-relevant signage for global application",
"timestamp": "1 day ago",
"publisher": "The Hindu Businessline"
},
{
"href": "https://www.business-standard.com/article/news-cm/apar-industries-ltd-leads-losers-in-a-group-121042701094_1.html",
"headline": "Apar Industries Ltd leads losers in ‘A’ group",
"timestamp": "6 days ago",
"publisher": "Business Standard"
}
]
}
... OTHER FIELDS ...
}
I need to break each of these documents wrt News.Bites array field data like the following example:
{
"Name": "3m india ltd.",
"BSECode": "523395",
"NSECode": "3MINDIA",
"News": {
"href": "https://www.thehindubusinessline.com/companies/3m-india-develops-cleaning-solution-covid-relevant-signage-for-global-application/article34462888.ece",
"headline": "3M India develops cleaning solution, Covid-relevant signage for global application",
"timestamp": "1 day ago",
"publisher": "The Hindu Businessline"
}
},
{
"Name": "3m india ltd.",
"BSECode": "523395",
"NSECode": "3MINDIA",
"News": {
"href": "https://www.business-standard.com/article/news-cm/apar-industries-ltd-leads-losers-in-a-group-121042701094_1.html",
"headline": "Apar Industries Ltd leads losers in ‘A’ group",
"timestamp": "6 days ago",
"publisher": "Business Standard"
}
}
This is the projection query I have come up with yet:
coll.find({
'News': {
'$exists': true
}
}, {
'_id': 0,
'News.Bites': 1,
'NSECode': 1,
'BSECode': 1,
'Name': 1
});
Can anyone please help with this?
Hello Good Developers,
I am trying to implement embedsMany relationship of jenssegers/laravel-mongodb
I have two collections:
ProfileSection - {
"_id": "5c865ea4257db43fe4007331",
"general_name": "MY_PROFILE",
"type": "public",
"points": 100,
"status": 1,
"translated": [
{
"con_lang": "US-EN",
"country_code": "US",
"language": "EN",
"text": "My Profile",
"description": "My Profile"
},
...
],
"updated_at": "2019-03-11T13:12:04.000Z",
"created_at": "2019-03-11T13:12:04.000Z"
}
Profile Questions - {
"_id": "5c865ea3257db43fe40072b2",
"id": "STANDARD_EDUCATION",
"general_name": "STANDARD_EDUCATION",
"country_code": "US",
"order": 1,
"profile_section_id": "5c865ea4257db43fe4007331",
"profile_section": "My Profile",
"translated": [
{
"con_lang": "US-EN",
"text": "What is the highest level of education you have completed?",
"hint": null,
"mapping": {},
"answers": [
{
"precode": "1",
"text": "3rd Grade or less",
"mapping": {}
}
]
},
{...}
],
"updated_at": "2019-03-11T13:12:03.000Z",
"created_at": "2019-03-11T13:12:03.000Z"
}
In ProfileSection I have added
public function questions()
{
return $this->embedsMany(ProfilerQuestions::class, '_id', 'profile_section_id');
}
If I execute ProfileSection::find('5c865ea4257db43fe4007331')->questions
It returns me Profile Questions Object with only one attribute: 5c865ea4257db43fe4007331 i.e ObjectId of Profile Section
I tried using ->with('questions) before accessing questions object
like this
but it's not working
I don't understand what's the issue will definitely need some help.
i'm getting callbacks from facebook and response like this ;
{
"object": "page",
"entry": [
{
"id": "2407411660blabla",
"time": 1450266812,
"changes": [
{
"field": "feed",
"value": {
"item": "comment",
"verb": "add",
"comment_id": "787904161316072_blabla",
"post_id": "240741166032377_blabla",
"parent_id": "240741166032377_blabla",
"sender_id": 1020447568blabla,
"created_time": 1450266812,
"message": "blalba lba lba bla",
"sender_name": "Mehmet Tubay Saban"
}
}
]
}
As you can see , there are two array in this json;
1- entry[]
2- changes[]
Sometimes "entry array" has 1 or more items and some times "changes array" has 1 or more items , what is different between entry and changes array of objects ?
It seems to be based on the "time" value.
If several actions has the same "time" value they will appear in the changes[] array.
I have some documents in the "company" collection structured this way :
[
{
"company_name": "Company 1",
"contacts": {
"main": {
"email": "main#company1.com",
"name": "Mainuser"
},
"store1": {
"email": "store1#company1.com",
"name": "Store1 user"
},
"store2": {
"email": "store2#company1.com",
"name": "Store2 user"
}
}
},
{
"company_name": "Company 2",
"contacts": {
"main": {
"email": "main#company2.com",
"name": "Mainuser"
},
"store1": {
"email": "store1#company2.com",
"name": "Store1 user"
},
"store2": {
"email": "store2#company2.com",
"name": "Store2 user"
}
}
}
]
I'm trying to retrieve the doc that have store1#company2.com as a contact but cannot find how to query a specific value of a specific propertie of an "indexed" list of objects.
My feeling is that the contacts lists should not not be indexed resulting in the following structure :
{
"company_name": "Company 1",
"contacts": [
{
"email": "main#company1.com",
"name": "Mainuser",
"label": "main"
},
{
"email": "store1#company1.com",
"name": "Store1 user",
"label": "store1"
},
{
"email": "store2#company1.com",
"name": "Store2 user",
"label": "store2"
}
]
}
This way I can retrieve matching documents through the following request :
db.company.find({"contacts.email":"main#company1.com"})
But is there anyway to do a similar request on document using the previous structure ?
Thanks a lot for your answers!
P.S. : same question for documents structured this way :
{
"company_name": "Company 1",
"contacts": {
"0": {
"email": "main#company1.com",
"name": "Mainuser"
},
"4": {
"email": "store1#company1.com",
"name": "Store1 user"
},
"1": {
"email": "store2#company1.com",
"name": "Store2 user"
}
}
}
Short answer: yes, they can be queried but it's probably not what you want and it's not going to be really efficient.
The document structure in the first and third block is basically the same - you have an embedded document. The only difference between are the name of the keys in the contacts object.
To query document with that kind of structure you will have to do a query like this:
db.company.find({ $or : [
{"contacts.main.email":"main#company1.com"},
{"contacts.store1.email":"main#company1.com"},
{"contacts.store2.email":"main#company1.com"}
]});
This query will not be efficient, especially if you have a lot of keys in the contacts object. Also, creating a query will be unnecessarily difficult and error prone.
The second document structure, with an array of embedded objects, is optimal. You can create a multikey index on the contacts array which will make your query faster. The bonus is that you can use a short and simple query.
I think the easiest is really to shape your document using the structure describe in your 2nd example : (I have not fixed the JSON)
{
"company_name": "Company 1",
"contacts":{[
{"email":"main#company1.com","name":"Mainuser", "label": "main", ...}
{"email":"store1#company1.com","name":"Store1 user", "label": "store1",...}
{"email":"store2#company1.com","name":"Store2 user", "label": "store2",...}
]}
}
like that you can easily query on email independently of the "label".
So if you really want to use the other structure, (but you need to fix the JSON too) you will have to write more complex code/aggregation pipeline, since we do not know the name and number of attributes when querying the system. Theses structures are also probably hard to use by the developers independently of MongoDB queries.
Since it was not clear let me show what I have in mind
db.company.save(
{
"company_name": "Company 1",
"contacts":[
{"email":"main#company1.com","name":"Mainuser", "label": "main"},
{"email":"store1#company1.com","name":"Store1 user", "label": "store1"},
{"email":"store2#company1.com","name":"Store2 user", "label": "store2"}
]
}
);
db.company.save(
{
"company_name": "Company 2",
"contacts":[
{"email":"main#company2.com","name":"Mainuser", "label": "main"},
{"email":"store1#company2.com","name":"Store1 user", "label": "store1"},
{"email":"store2#company2.com","name":"Store2 user", "label": "store2"}
]
}
);
db.company.ensureIndex( { "contacts.email" : 1 } );
db.company.find( { "contacts.email" : "store1#company2.com" } );
This allows you to store many emails, and query with an index.