Mongodb query to add a review into reviews - mongodb

hi i have made a query to add a new review into the reviews array of an existing listing. this is the code im working with and i dont know where i went wrong with it . the second part is the example reviews
db.listingsandreviews.updateOne[
{reviews:{
"_id": "58663769",
"date": {
"$date": {
"$numberLong": "1451797200000"
}
},
{"listing_id": "10006546",
"reviewer_id": "51483090",
"reviewer_name": "Michelle",
"comments": "The place was really nice and the host are friendly with us"
}}}]
_id
"403055315"
date
2019-01-20T05:00:00.000+00:00
listing_id
"10006546"
reviewer_id
"15138940"
reviewer_name
"Milo"
comments
"The house was extremely well located and Ana was able to give us some …"

Not clear what the problem is, but from the description you may be missing $push operator to add review into existing reviews.
https://www.mongodb.com/docs/manual/reference/operator/update/push/#examples
If you can provide proper queries that you run and problem, we may be able to help better, for example currently "updateOne[" will cause error, as it should be "updateOne(".

Related

How do I perform aggregate queries using SumoLogic APIs

I am trying to perform aggregate queries using SumoLogic APIs as mentioned here.
Something like:
_view = <some_view> | where sourceCategory matches \"something\" | sum(field) by sourceCategory
This works just fine in the Sumo GUI. I get a field in result called "_sum" which gives me the desired result.
However the same doesn't work when I do it using the SUMO APIs. If I create a job with this body:
{
"query": "_view = <some_view> | where sourceCategory matches "something" | sum(field) by sourceCategory",
"from": "start_timestamp",
"to": "end_timestamp",
"timeZone": "some_timezone"
}
I call the "v1/search/jobs" POST method with the above body and I do GET "v1/search/jobs/{job_id}" till the state is "DONE GATHERING RESULTS". Then I do "v1/search/jobs/{job_id}/messages". I was expecting to see aggregated values in the result, but instead I see something similar to:
{
"fields":[
{
"name":"_messageid",
"fieldType":"long",
"keyField":false
}, ...
],
"messages":[
{
"map":{
"_receipttime":"1359407350899",
"_size":"549",
"_sourcecategory":"service",
"_sourceid":"1640",
"the_field_i_mentioned":"not-aggregated-value"
"_messagecount":"2044"
}
}, ...
]
]
Thanks for going through my question. Any advices / work-arounds are appreciated. I don't really want to iterate manually through all items and calculate the sum. I'd prefer to do it on SumoLogic side itself. Thanks Again!
Explanation
Similar as in the User Interface, in the API for log searches you get both raw results (also referred to as messages) and the aggregate results (also referred to as records).
(Obviously, the latter are only returned if there's any aggregation in the query. In your case there is.)
Actual suggestion
Then I do "v1/search/jobs/{job_id}/messages"
Try /records instead.
See the docs for "Paging through the records found by a Search Job"
Disclaimer: I am currently employed by Sumo Logic.

Avoid duplicated nested objects within the same document ONLY

Hello Everybody i'm so sorry to ask but i've been trying to look for an answer for MONTHS, and im already desperate because i can't seem to find what i need till the point that i'm almost giving up with NoSQL.
So here's my Schema.
I have States of a Country and they have their non-repeatable ISO CODE,
{
code: 'US-NY',
name: 'New York',
cities: [ ]
},
etc ..
.. however inside the state (nested objects) we have cities:
cities:[
{
code: 'new-york',
name:'New York',
},
{
code: 'bufalo',
name:'Búfalo',
},
]
So when i add a document, i want to avoid duplicated nested objects (cities) with the same code (example: 'bufalo') within the same document (state).
BUT i could use 'bufalo' in another document (state).
When i set an index to cities.code to be Unique, it applies in the whole collection, and i want to use that code in another document.
I would like to repeat 'bufalo' city code in another document (state), but i dont want it to be repeated in the same document.
How could i archive this? Thank you so much for your kind help, i will be checking this post desperately.
Thanks
Alan D.

Amadeus Hotel Search returning empty array on some cities

im having the following error with my Amadeus API integration, with the following hit as example:
https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=MAD&roomQuantity=1&adults=2&radius=5&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=NONE
In this example, im trying to find hotels in the MAD IATA code, which can be either Barajas Airport, or Madrid itself. This throws response 200 (meaning OK), but the data is empty like no hotels.
Another example of this happening is in AMS (Amsterdam or the airport itself)
I thought it could be some crash between cities and airport with the same IATA code, but BCN (Barcelona and El Pratt airport) works fine.
Have anyone else faced this issue?
I just tried your example in test and it works for me:
https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=MAD&roomQuantity=1&adults=2&radius=5&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=NONE
"type": "hotel",
"hotelId": "BWMAD200",
"chainCode": "BW",
"dupeId": "700009576",
"name": "BEST WESTERN HOTEL LOS CONDES",
...
2 things to keep in mind:
You use the test environment, in this environment the data set is limited (enough to prototype) if you want to get access to the full set of data you will have to move to production.
You are doing a hotel search, it could that it didn't find available rooms at the moment you did the request for the provided parameters (link to the previous point where the data set is limited). You can play with the radius and the roomQuantity to find more hotels.
I'm seeing this too.
I cannot find a combination of fields that returns any data for any of the MAD or NYC city codes.
LON is the only city code that I can get search results from, but only if I specify dates earlier than April.
Searching for MAD without dates
Query:
https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=MAD&roomQuantity=1&adults=2&radius=5&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=NONE
Results:
{
"data": [],
"meta": {
"links": {
"next": "https://test.api.amadeus.com/v2/shopping/hotel-offers?adults=2&bestRateOnly=true&cityCode=MAD&includeClosed=false&paymentPolicy=NONE&radius=5&radiusUnit=KM&roomQuantity=1&sort=NONE&view=FULL&page[offset]=H0227D1ADVO9_100"
}
}
}
Searching for LON in April
Query:
https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=LON&checkInDate=2020-04-04&checkOutDate=2020-04-09&roomQuantity=1&adults=2&radius=5&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=NONE
Results:
{
"data": [],
"meta": {
"links": {
"next": "https://test.api.amadeus.com/v2/shopping/hotel-offers?adults=2&bestRateOnly=true&checkInDate=2020-04-04&checkOutDate=2020-04-09&cityCode=LON&includeClosed=false&paymentPolicy=NONE&radius=5&radiusUnit=KM&roomQuantity=1&sort=NONE&view=FULL&page[offset]=IHNILC3OTZSM_100"
}
}
}
Searching for LON in March
Query:
https://test.api.amadeus.com/v2/shopping/hotel-offers?cityCode=LON&checkInDate=2020-03-04&checkOutDate=2020-03-09&roomQuantity=1&adults=2&radius=5&radiusUnit=KM&paymentPolicy=NONE&includeClosed=false&bestRateOnly=true&view=FULL&sort=NONE
Results:
Success
I agree that it's not very clear which searches we should expect to be successful. Is there a date limitation that I'm not aware of? Which cities are supported?
The only information around what limitations we should expect from hotel searches in the test environment that I've seen seems to code from your test dataset repository:
The content of Hotel Search comes directly from the hotel providers, so the content might change dynamically. For your test, use big cities like LON (London) or NYC (New-York).

MongoDB get last 10 activities

In My social network I want to get the feed for member A , member A is following lets say 20 category/member.
when a category/member(followed by member A) do an activity it is inserted into a collection called recent_activity :
{
"content_id": "6", // content id member A is following
"content_type_id": "6",// content type (category , other member)
"social_network_id": "2", // the action category did (add/like/follow)
"member_id": "51758", //Member A
"date_added": ISODate("2014-03-23T11:37:03.0Z"),
"platform_id": NumberInt(2),
"_id": ObjectId("532ec75f6b1f76fa2d8b457b"),
"_type": {
"0": "Altibbi_Mongo_RecentActivity"
}
}
I want when member A login into the system to get last 10 activities for the categories/member
my problem :
How to get Only 10 activities for all categories/members.
It is better to do it in one query or to do a for loop.
For this use case, I'd suggest to invert the logic and keep a separate object of the last 10 activities for member A that is kept up-to-date all the time. While that solution is more write-heavy, it makes reading trivially simple and it can be extended very easily. I'd like to blatantly advertise a blog post I wrote a while ago about news feeds with mongodb which outlines this approach.
This 'fan-out' approach might seem overly complex at first, but when you think about importance filtering / ranking (a la facebook), push messages for particularly important events (facebook, twitter) or regular digest emails (practically all), you will get one location in your code to perform all this logic.
I think I commented that T'm not really seeing the selection criteria. So if you are "outside" of a single collection, then you have problems. But if your indicated fields are the things you want to "filter" by, then just do this:
db.collection.find({
"social_network_id": "2",
"content_type_id": "6",
"content_id": "6",
"member_id": { "$ne": "51758" }
})
.sort({ "$natural": -1 })
.limit(10);
So what does that do? You match the various conditions in the data to do the "category match" (if I understood what was meant), then you make sure you are not matching entries by the same member.
The last parts do the "natural" sort. This is important because the ObjectId is monotinic, or math speak for "ever increasing". This means the "newest" entries are always the "highest" value. So descending order is "latest" to "oldest".
And the very final part is a basic "limit". So just return the last 10 entries.
As long as you can "filter" within the same collection in whatever way you want, then this should be fine.

iTunes Search API returning extra, incorrect results

I've been using the iTunes API in my app for a while now, but as of the last few days I've noticed that it is returning odd results. I currently use it to search for software however it's now started adding Software Artists to the results which I believe to be incorrect with the search parameters. Below is a URL searching for my app, and below that is the returned JSON.
http://itunes.apple.com/search?term=AppTracker%20Deluxe&limit=100&entity=software&lang=en_GB&country=GB
{
"resultCount":2,
"results": [
{"kind":"software", "features":[],
"supportedDevices":["iPhone5s", "iPadMini", "iPhone5c", "iPadFourthGen", "iPad2Wifi","iPad23G", "iPadThirdGen", "iPhone5", "iPodTouchFifthGen", "iPadThirdGen4G", "iPhone4", "iPadFourthGen4G", "iPadMini4G", "iPhone4S"], "isGameCenterEnabled":false, "
cutting most stuff out for space
"languageCodesISO2A":["EN", "FR", "DE", "IT", "ZH", "ES"], "fileSizeBytes":"3575818", "trackContentRating":"4+", "averageUserRating":5.0, "userRatingCount":5},
{"wrapperType":"artist", "artistType":"Software Artist", "artistName":"Handyman Interactive", "artistLinkUrl":"https://itunes.apple.com/gb/artist/handyman-interactive/id586907831?uo=4", "artistId":586907831}]
}
As you can see, on top of returning the correct app, it is returning a software artist (myself in this case) which it hasn't done in the past. Obviously I can update the app to ignore these, but for the current version of my app it is causing slight bugs. Is this a problem down apples end or is it intended?
Thanks for the help,
Mike
Turns out it was a bug and the behaviour is no longer present.
Mike