在find的猫鼬查询(“ -_id services.location”)上,字符串化的输出为:
mInterstitialAd = new InterstitialAd(this);
/*mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());*/
mInterstitialAd.setAdUnitId(String.valueOf(R.string.admob_interstitial_ad_id));
mInterstitialAd.loadAd(new AdRequest.Builder().build());
//.addTestDevice("25E662D1EDF4290XXXXXXXXXXXX")
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
Log.e("TAG", "ADMOB INTERSTITIAL AD - " + i);
}
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
有什么办法可以从我得到的输出中访问位置的每个单独值,例如(17.4374614,78.7482878,17.4020637 ....)
我的架构如下:-
[
{
"services":[
{
"location":[
17.4374614,
78.7482878
]
},
{
"location":[
17.4020637,
78.18400519324596
]
},
{
"location":[
17.56208737,
78.284005186526
]
},
{
"location":[
17.5620637,
78.3240051999554
]
}
]
}
]
答案 0 :(得分:1)
您正在寻找的是$reduce
和$concatArrays
运算符。
[
{
"$project": {
"result": {
"$reduce": {
"input": "$services.location",
"initialValue": [],
"in": {
"$concatArrays": [
"$$this",
"$$value"
]
}
}
}
}
}
]
答案 1 :(得分:0)
更新了以下答案:
有什么方法可以只渲染不带_id的loc值数组 进入模板。我只需要渲染loc数组的值
您可以通过以下方法进行操作:https://mongoplayground.net/p/VhrZKxg6OC1
db.collection.aggregate([
{
$unwind: "$services"
},
{
$unwind: "$services.location"
},
{
$project: {
"_id": "$_id",
"location": "$services.location"
}
},
{
$group: {
_id: "_id",
loc: {
$push: "$location"
}
}
},
{
$project: {
"_id": 0,
"locationArray": "$loc"
}
}
])
这将导致:
[
{
"locationArray": [
17.4374614,
78.7482878,
17.4020637,
78.18400519324597,
17.56208737,
78.284005186526,
17.5620637,
78.3240051999554
]
}
]
希望它可以解决您的查询。