I have a JSON schema that looks like this:
{
"_id" : ObjectId("5692a3e124de1e0ce2dfda22"),
"title" : "A Decade of Decadence, Pt. 2: Legacy of Dreams",
"year" : 2013,
"rated" : "PG-13",
"released" : ISODate("2013-09-13T04:00:00Z"),
"runtime" : 65,
"countries" : [
"USA"
],
"genres" : [
"Documentary"
],
"director" : "Drew Glick",
"writers" : [
"Drew Glick"
],
"actors" : [
"Gordon Auld",
"Howie Boulware Jr.",
"Tod Boulware",
"Chen Drachman"
],
"plot" : "A behind the scenes look at the making of A Tiger in the Dark: The Decadence Saga.",
"poster" : null,
"imdb" : {
"id" : "tt2199902",
"rating" : 8,
"votes" : 50
},
"awards" : {
"wins" : 0,
"nominations" : 0,
"text" : ""
},
"type" : "movie"
}
I am trying to find a movie released in 2013, that is rated PG-13 and has won no awards. I tried the following query in my Mongo Shell but no luck:
db.movieDetails.find({rated: "PG-13", year:2013, awards: { wins : 0}})
Any ideas?
From the documentation:
When the field holds an embedded document, a query can either specify an exact match on the embedded document or specify a match by individual fields in the embedded document using the dot notation
db.movieDetails.find( { "rated": "PG-13", "year": 2013, "awards.wins" : 0 } )
if this PG-13 rating query would work for you:
db.movieDetails.find({"rated": "PG-13"})
then i would try something like this:
db.movieDetails.find({$and: [{"rated": "PG-13"}, {"year": 2013}, {"awards": { "wins" : 0}}]} )
Related
I want to create a view which fields are come from two different object array with seperate collections.For more explanation here is my code
{
"_id" : ObjectId("5e4173cf51af9f555e64531c"),
"__v" : 0,
"createdDate" : ISODate("2020-02-24T08:33:24.100Z"),
"maxDate" : {
"month" : 12,
"year" : 2018
},
"modifiedDate" : ISODate("2020-02-24T08:33:33.025Z"),
"stockArray" : [
{
"purchase_bill_date" : "1/9/2017",
"purchase_bill_series" : "A",
"purchase_bill_item_no" : "419905",
"stock_code" : "5372123-ANN",
},
{
"purchase_bill_date" : "1/9/2017",
"purchase_bill_series" : "A",
"purchase_bill_item_no" : "419905",
"stock_name" : "53743N-10-10S",
}]
}
and the other collection
{
"_id" : ObjectId("5e4173cf51af9f555e64531c"),
"__v" : 0,
"yuklenimReports" : [
{
"purchase_bill_date" : "9/3/2018",
"purchase_bill_series" : null,
"purchase_bill_item_no" : "419905",
""stock_name" : "53743N-10-10S"
}]
}
i want to inner join purchase_bill_item_no and show the others.But i couldnt handle i spent too much hour to find the solution.Thanks for all help.
I'm looking to build a pretty basic address search functionality inside of my iOS app. I'm using Google Places Autocomplete to query for results based on users input, like below:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=shoppers#&radius=160934&location=50.445210,-104.618896&components=country:ca&key=xxxxxxxxxxxxx
The results I'm getting back are far too vague to be of practical use. Below is one example, where all I get is the name of the business and the street that it is on. Problem being, there are three different locations for this business on the same street, so how would the user be able to figure out which one they're selecting without being provided a street number?
{
"description" : "Shoppers Drug Mart, Albert Street, Regina, SK, Canada",
"id" : "94065830c922a4239ece26102fb3439fa2f2e155",
"matched_substrings" : [
{
"length" : 8,
"offset" : 0
}
],
"place_id" : "ChIJ4XzAGbCgHlMRGSFBsEbyfCE",
"reference" : "ChIJ4XzAGbCgHlMRGSFBsEbyfCE",
"structured_formatting" : {
"main_text" : "Shoppers Drug Mart",
"main_text_matched_substrings" : [
{
"length" : 8,
"offset" : 0
}
],
"secondary_text" : "Albert Street, Regina, SK, Canada"
},
"terms" : [
{
"offset" : 0,
"value" : "Shoppers Drug Mart"
},
{
"offset" : 20,
"value" : "Albert Street"
},
{
"offset" : 35,
"value" : "Regina"
},
{
"offset" : 43,
"value" : "SK"
},
{
"offset" : 47,
"value" : "Canada"
}
],
"types" : [ "pharmacy", "health", "point_of_interest", "store", "establishment" ]
},
Places Autocomplete is not designed to return detailed address information. It is designed to return predictions based on your input. You then have to use the Place ID that gets returned and make a Place Details request using it to get a response that includes address information, etc.
Using the first result from your autocomplete request, I can form a Place Details request like:
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ4XzAGbCgHlMRGSFBsEbyfCE&key=YOUR_API_KEY
That will give the information you desire.
https://developers.google.com/places/web-service/autocomplete#place_autocomplete_results
https://developers.google.com/places/web-service/place-id#example-using-the-places-api
I have 2 Json values that are similar, but there are some differences.
Json1:
{
"id": "1",
"people" : [
{
"Id" : 1421,
"Name" : "Jackson",
"Age" : 21,
"Status" : "Available"
},
{
"Id" : 5916,
"Name" : "Steven",
"Age" : 22,
"Status" : "Available"
}
],
"totalRecords" : 2
}
Json2:
{
"id": "1",
"people" : [
{
"Id" : 1421,
"Name" : "Jackson",
"Age" : 21,
"Status" : "Available"
},
{
"Id" : 5916,
"Name" : "Steven",
"Age" : 22,
"Status" : "Unavailable"
},
{
"Id" : 1337,
"Name" : "Alice",
"Age" : 19,
"Status" : "Available"
}
],
"totalRecords" : 3
}
I'd like to know if there's a way to compare the two Jsonvalues. At the moment I de-serialize the data into a type and then use the Id's and the status' to see if anythings changed. I then pick out the parts that are different (In the example it'd be Steven and Alice) and add them to a sequence for later.
I'd like to reverse a few of the steps. I'd like too compare the json, find the differences, deserialize them and then add them to the sequence, or add them to the sequence then de-serialize the whole sequence. Either way, same result.
Any ideas?
I currently have a Mongo DB database with one collection ('locations') with one document:
{
"_id" : ObjectId("5875653b89513c8328416522"),
"name" : "Starcups",
"address" : "125 High Street, Reading, RG6 1PS",
"rating" : 3,
"facilities" : [
"Hot drinks",
"Food",
"Premium wifi"
],
"coords" : [
-0.9690884,
51.455041
],
"openingTimes" : [
{
"days" : "Monday - Friday",
"opening" : "7:00am",
"closing" : "7:00pm",
"closed" : false
},
{
"days" : "Saturday",
"opening" : "8:00am",
"closing" : "5:00pm",
"closed" : false
},
{
"days" : "Sunday",
"closed" : true
}
],
"reviews" : [
{
"author" : "Simon Holmes",
"id" : ObjectId("5875663389513c8328416523"),
"rating" : 5,
"timestamp" : ISODate("2013-07-15T23:00:00Z"),
"reviewText" : "What a great place. I can't say enough good things about it."
}
]
}
I need to alter the field "id" (part of the subdocument reviews) to "_id". I have tried, using other similar examples on StackExchange, the following code to no avail:
db.locations.update({}, {$rename:{"reviews.id":"reviews._id"}}, false, true);
But I receive the following error:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16837,
"errmsg" : "cannot use the part (reviews of reviews.id) to traverse the element ({reviews: [ { author: \"Simon Holmes\", id: ObjectId('5875663389513c8328416523'), rating: 5.0, timestamp: new Date(1373929200000), reviewText: \"What a great place. I can't say enough good things about it.\" } ]})"
}
})
I get the same error when I try to alter any other field. Could someone point me in the right direction?
Update:
This seems to be a problem assessing the subdocument field as the following code executes fine:
db.locations.update({}, {$rename:{"name":"names"}}, false, true);
I have also tried searching through the relevant documentation: https://docs.mongodb.com/manual/reference/operator/update/rename/
That's because Reviews is an Array
You cannot $rename to do that , instead you need to $set the new name and $unset the old one
I am using google.maps.places.AutocompleteService(); to get query predictions. Is it possible to omit country name from the predictions list of users location. For eaxmple. if i am in united states, when i search for sanfransisco. It should not show United states (Country name) in predictions list. But if i search for location- delhi in india, it should show 'Delhi India'(country name).
Is this possible using this service or any other google api service.
Note that, i need list of suggestion, not something tied with a textfield.
Your help will be greatly appreciated.
This is not possible without manually processing the results. So after receiving the json data as a response, you need to check if the suggested country is the same as the user's country and if it is then do not display it in the textfield.
A JSON response looks like this: In the value field you can check the country and decide whether or not to display it by comparing it to the user's country that needs to be set somewhere in your App.
I believe the JSON response will be save in a List<HashMap<String, String>> So you can loop over it and omit the country.
{
"status": "OK",
"predictions" : [
{
"description" : "Paris, France",
"id" : "691b237b0322f28988f3ce03e321ff72a12167fd",
"matched_substrings" : [
{
"length" : 5,
"offset" : 0
}
],
"place_id" : "ChIJD7fiBh9u5kcRYJSMaMOCCwQ",
"reference" : "CjQlAAAA_KB6EEceSTfkteSSF6U0pvumHCoLUboRcDlAH05N1pZJLmOQbYmboEi0SwXBSoI2EhAhj249tFDCVh4R-PXZkPK8GhTBmp_6_lWljaf1joVs1SH2ttB_tw",
"terms" : [
{
"offset" : 0,
"value" : "Paris"
},
{
"offset" : 7,
"value" : "France"
}
],
"types" : [ "locality", "political", "geocode" ]
},
{
"description" : "Paris Avenue, Earlwood, New South Wales, Australia",
"id" : "359a75f8beff14b1c94f3d42c2aabfac2afbabad",
"matched_substrings" : [
{
"length" : 5,
"offset" : 0
}
],
"place_id" : "ChIJrU3KAHG6EmsR5Uwfrk7azrI",
"reference" : "CkQ2AAAARbzLE-tsSQPgwv8JKBaVtbjY48kInQo9tny0k07FOYb3Z_z_yDTFhQB_Ehpu-IKhvj8Msdb1rJlX7xMr9kfOVRIQVuL4tOtx9L7U8pC0Zx5bLBoUTFbw9R2lTn_EuBayhDvugt8T0Oo",
"terms" : [
{
"offset" : 0,
"value" : "Paris Avenue"
},
{
"offset" : 14,
"value" : "Earlwood"
},
{
"offset" : 24,
"value" : "New South Wales"
},
{
"offset" : 41,
"value" : "Australia"
}
],
...
Reference: https://developers.google.com/places/webservice/autocomplete#location_biasing