我正在Springboot应用程序中的Mongo Db中创建一个视图。下面是相同的代码
[{
$sort: {
event_trigger_date: -1
}
}, {
$group: {
_id: {
"profile_id": "$profile_id"
},
data: {
$first: "$$ROOT"
}
}
}, {
$unset: "_id"
}, {
$replaceRoot: {
newRoot: "$data"
}
}, {
$project: {
"profile_id": 1
}
}, {
$lookup: {
from: 'profile_event',
localField: 'profile_id',
foreignField: 'profile_id',
as: 'profile_event_data'
}
}, {
$group: {
_id: {
"profile_id": "$profile_id"
},
data: {
$first: "$$ROOT"
}
}
}, {
$replaceRoot: {
newRoot: "$data"
}
}, {
$project: {
profile_id: 1,
profile_event_data: 1,
event_type_set: {
$concatArrays: ["$profile_event_data.event_type"]
}
}
}, {
$addFields: {
_id: {
$concat: ["ACTIONS_NOT_COMPLETED_0X:", "$profile_id"]
},
event_type: "ACTIONS_NOT_COMPLETED_NX",
event_trigger_date: "$$NOW",
event_occurence: 0,
trigger_status: "SILENT"
}
}, {
$unset: "event_exists"
}, {
$lookup: {
from: 'profile_personal_info',
localField: 'profile_id',
foreignField: 'profile_id',
as: 'personal_info'
}
}, {
$project: {
profile_id: 1,
event_type: 1,
event_trigger_date: 1,
event_occurence: 1,
trigger_status: 1,
event_type_set: 1,
personal_info: {
$arrayElemAt: ["$personal_info", 0]
}
}
}, {
$addFields: {
oldest_personal_info_created_date: {
$trunc: {
$divide: [{
$subtract: ["$$NOW", '$personal_info.created_date']
}, 1000 * 60 * 60 * 24]
}
}
}
}, {
$addFields: {
created_date: {
$trunc: {
$divide: [{
$subtract: ["$$NOW", '$event_trigger_date']
}, 1000 * 60 * 60 * 24]
}
}
}
}, {
$project: {
event_type: 1,
profile_id: 1,
event_trigger_date: 1,
profile_event_data: 1,
event_type_set: 1,
event_occurence: 1,
trigger_status: 1,
category_value: {
$cond: {
if: {
$eq: ["$oldest_personal_info_created_date", null]
},
then: "$created_date",
else: "$oldest_personal_info_created_date"
}
}
}
}, {
$project: {
profile_id: 1,
event_type: 1,
event_type_set: 1,
event_trigger_date: 1,
event_occurence: 1,
trigger_status: 1,
category_value: 1,
"event_exists": {
$in: ["ACTIONS_NOT_COMPLETED_NX", "$event_type_set"]
}
}
}, {
$match: {
event_exists: {
$ne: true
}
}
}, {
$unset: ["event_exists", "event_type_set"]
}]
我想添加allowDiskUse:true条件,因为我得到以下错误
堆栈跟踪:|/java.lang.Exception:[profile_event_view@stage[副本集:]]数据库错误!|___/Mongo服务器错误(MongoQueryException):查询失败,错误代码为292,错误消息为“聚合期间出现PlanExecutor错误::由::Sort超出33554432字节的内存限制,但未选择外部排序。”
如何在我的代码中添加allowDiskUse: true以避免上述错误?
真的是一个巨大的管道。我认为有很大的优化空间。
例如,如果我没有记错,这些阶段
[
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"profile_event_data": 1,
"filteredList": { "$filter": { "input": "$profile_event_data", "as": "item", "cond": { "$eq": ["$$item.event_type", "ACTIONS_COMPLETED_DAILY"] } } }
}
},
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"profile_event_data": 1,
"filteredList": 1,
"lastfilteredlist": { "$arrayElemAt": ["$filteredList", -1] }
}
},
{ "$unset": ["profile_event_data", "filteredList"] },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"latest_daily_action_creation_date": "$lastfilteredlist.created_date"
}
},
{ "$addFields": { "latest_daily_action_created_date": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$latest_daily_action_creation_date"] }, 86400000] } } } },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"latest_daily_action_created_date": 1,
"category_value": { "$cond": { "if": { "$eq": ["$latest_daily_action_created_date", null] }, "then": "$oldest_lifebandinfo_created_date", "else": "$latest_daily_action_created_date" } }
}
},
{ "$unset": ["oldest_lifebandinfo_created_date", "latest_daily_action_created_date"] }]
]
您可以简单地编写如下。它不会使您的聚合管道更快,但更容易阅读:
[
{
"$set": {
"filteredList": { "$filter": { "input": "$profile_event_data", "as": "item", "cond": { "$eq": ["$$item.event_type", "ACTIONS_COMPLETED_DAILY"] } } }
}
},
{
"$project": {
"latest_daily_action_created_date": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", { "$arrayElemAt": ["$filteredList.created_date", -1] }] }, 86400000] } },
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"category_value": { "$cond": { "if": { "$eq": ["$latest_daily_action_created_date", null] }, "then": "$oldest_lifebandinfo_created_date", "else": "$latest_daily_action_created_date" } }
}
}
]
请注意,< code>$project中不存在的每个字段都将被删除。您也可以使用< code>"$$REMOVE"来代替单独的< code>$unset阶段,例如
{
"$addFields": {
"event_trigger_date": "$lifeband_info.created_date",
"filteredList": "$$REMOVE"
}
}
再比如:
[
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ "$project": { "profile_id": 1 } },
]
成为
[
{ "$project": { "profile_id": "$data.profile_id", _id: 0 } }
]
你跑了12次
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } }
尝试只运行一次,重复使用结果(即数据
字段)几次。操作<code>$setWindowFields</code>可以提供同样的效果,但需要花费更少的精力。
同样适用于18(!)$lookup
。每个集合只联接一次,并重用联接的数据。
重新格式化的管道:
db.profile_event.aggregate([
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{
"$project": {
"profile_id": 1
}
},
{ "$lookup": { "from": "profile_event", "localField": "profile_id", "foreignField": "profile_id", "as": "profile_event_data" } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$replaceRoot": { "newRoot": "$data" } },
{
"$project": {
"profile_id": 1,
"profile_event_data": 1,
"event_type_set": { "$concatArrays": ["$profile_event_data.event_type"] }
}
},
{
"$addFields": {
"_id": { "$concat": ["ACTIONS_NOT_COMPLETED_0X:", "$profile_id"] },
"event_type": "ACTIONS_NOT_COMPLETED_NX",
"event_trigger_date": "$$NOW",
"event_occurence": 0,
"trigger_status": "SILENT"
}
},
{ "$unset": "event_exists" },
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_id", "foreignField": "profile_id", "as": "lifeband_info" } },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"event_type_set": 1,
"lifeband_info": { "$arrayElemAt": ["$lifeband_info", 0] }
}
},
{ "$addFields": { "oldest_lifebandinfo_created_date": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$lifeband_info.created_date"] }, 86400000] } } } },
{ "$addFields": { "created_date": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$event_trigger_date"] }, 86400000] } } } },
{
"$project": {
"event_type": 1,
"profile_id": 1,
"event_trigger_date": 1,
"profile_event_data": 1,
"event_type_set": 1,
"event_occurence": 1,
"trigger_status": 1,
"category_value": { "$cond": { "if": { "$eq": ["$oldest_lifebandinfo_created_date", null] }, "then": "$created_date", "else": "$oldest_lifebandinfo_created_date" } }
}
},
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_type_set": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1, "category_value": 1, "event_exists": { "$in": ["ACTIONS_NOT_COMPLETED_NX", "$event_type_set"] }
}
},
{ "$match": { "event_exists": { "$ne": true } } },
{ "$unset": ["event_exists", "event_type_set"] },
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$match": { "event_type": { "$eq": "ACTIONS_NOT_COMPLETED_NX" } } },
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ "$unset": ["last_modified_date", "notification_type", "progress_status"] },
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_id", "foreignField": "profile_id", "as": "lifeband_info" } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$replaceRoot": { "newRoot": "$data" } },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"filteredList": 1,
"lifeband_info": { "$arrayElemAt": ["$lifeband_info", 0] }
}
},
{ "$addFields": { "oldest_lifebandinfo_created_date": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$lifeband_info.created_date"] }, 86400000] } } } },
{ "$lookup": { "from": "profile_event", "localField": "profile_id", "foreignField": "profile_id", "as": "profile_event_data" } },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"profile_event_data": 1,
"filteredList": { "$filter": { "input": "$profile_event_data", "as": "item", "cond": { "$eq": ["$$item.event_type", "ACTIONS_COMPLETED_DAILY"] } } }
}
},
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"profile_event_data": 1,
"filteredList": 1,
"lastfilteredlist": { "$arrayElemAt": ["$filteredList", -1] }
}
},
{ "$unset": ["profile_event_data", "filteredList"] },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"latest_daily_action_creation_date": "$lastfilteredlist.created_date"
}
},
{ "$addFields": { "latest_daily_action_created_date": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$latest_daily_action_creation_date"] }, 86400000] } } } },
{
"$project": {
"profile_id": 1,
"event_type": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"oldest_lifebandinfo_created_date": 1,
"latest_daily_action_created_date": 1,
"category_value": { "$cond": { "if": { "$eq": ["$latest_daily_action_created_date", null] }, "then": "$oldest_lifebandinfo_created_date", "else": "$latest_daily_action_created_date" } }
}
},
{ "$unset": ["oldest_lifebandinfo_created_date", "latest_daily_action_created_date"] }]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ "$project": { "profile_id": 1 } },
{ "$lookup": { "from": "profile_event", "localField": "profile_id", "foreignField": "profile_id", "as": "profile_event_data" } },
{
"$project": {
"profile_id": 1,
"event_type_set": { "$concatArrays": ["$profile_event_data.event_type"] }
}
},
{
"$project": {
"profile_id": 1,
"event_exists": { "$in": ["HEALTH_FACTORS_NX", "$event_type_set"] }
}
},
{ "$match": { "event_exists": { "$ne": true } } },
{
"$addFields": {
"_id": { "$concat": ["HEALTH_FACTORS_0X:", "$profile_id"] },
"event_type": "HEALTH_FACTORS_NX",
"event_occurence": 0,
"trigger_status": "SILENT"
}
},
{ "$unset": "event_exists" },
{
"$addFields": {
"lifeband_event_id": { "$concat": ["lifeband:", "$profile_id"] }
}
},
{ "$lookup": { "from": "profile_event", "localField": "lifeband_event_id", "foreignField": "_id", "as": "lifeband" } },
{
"$project": {
"event_type": 1,
"profile_id": 1,
"event_occurence": 1,
"lifeband": { "$arrayElemAt": ["$lifeband", 0] },
"trigger_status": 1
}
},
{
"$addFields": {
"lifeband_last_modified_date": "$lifeband.last_modified_date",
"lifeband_last_modified_days": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$lifeband.last_modified_date"] }, 86400000] } }
}
},
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_id", "foreignField": "profile_id", "as": "lifeband_info" } },
{
"$project": {
"event_type": 1,
"profile_id": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"lifeband_last_modified_days": 1,
"lifeband_last_modified_date": 1,
"lifeband": 1,
"trigger_status": 1, "lifeband_info": { "$arrayElemAt": ["$lifeband_info", 0] }
}
},
{
"$addFields": {
"lifeband_info_event_trigger_date": "$lifeband_info.created_date",
"lifeband_info_event_trigger_days": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$lifeband_info.created_date"] }, 86400000] } }
}
},
{
"$project": {
"event_type": 1,
"profile_id": 1,
"event_trigger_date": { "$cond": { "if": { "$eq": ["$lifeband_last_modified_date", null] }, "then": "$lifeband_info_event_trigger_date", "else": "$lifeband_last_modified_date" } },
"event_occurence": 1,
"trigger_status": 1,
"lifeband_info_event_trigger_date": 1,
"lifeband_info_event_trigger_days": 1,
"lifeband_last_modified_days": 1,
"lifeband_last_modified_date": 1,
"category_value": { "$cond": { "if": { "$eq": ["$lifeband_last_modified_days", null] }, "then": "$lifeband_info_event_trigger_days", "else": "$lifeband_last_modified_days" } }
}
},
{ "$unset": ["lifeband_last_modified_days", "lifeband_info_event_trigger_days", "lifeband_last_modified_date", "lifeband_info_event_trigger_date"] }]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$match": { "event_type": { "$eq": "HEALTH_FACTORS_NX" } } },
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{
"$addFields": {
"category_value": { "$trunc": { "$divide": [{ "$subtract": ["$$NOW", "$event_trigger_date"] }, 86400000] } }
}
},
{ "$unset": ["last_modified_date", "notification_type", "progress_status"] }]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_id", "foreignField": "profile_id", "as": "lifeband_info" } },
{
"$project": {
"profile_id": 1,
"lifeband_info": { "$arrayElemAt": ["$lifeband_info", 0] }
}
},
{ "$addFields": { "category_value": { "$abs": { "$subtract": [{ "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.max" }, { "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.min" }] } } } },
{
"$project": {
"profile_id": 1,
"category_value": 1
}
},
{ "$lookup": { "from": "profile_event", "localField": "profile_id", "foreignField": "profile_id", "as": "profile_event_data" } },
{
"$project": {
"profile_id": 1,
"category_value": 1,
"event_type_set": { "$concatArrays": ["$profile_event_data.event_type"] }
}
},
{
"$project": {
"profile_id": 1,
"category_value": 1,
"event_exists": { "$in": ["JUVBAND_ACCURACY_LOW_NX", "$event_type_set"] }
}
},
{ "$match": { "event_exists": { "$ne": true } } },
{
"$addFields": {
"_id": { "$concat": ["JUVBAND_ACCURACY_LOW_0X:", "$profile_id"] },
"event_type": "JUVBAND_ACCURACY_LOW_NX",
"event_trigger_date": "$$NOW",
"event_occurence": 0,
"trigger_status": "SILENT"
}
},
{ "$unset": "event_exists" }]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$match": { "event_type": { "$eq": "JUVBAND_ACCURACY_LOW_NX" } } },
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" },
{ "$replaceRoot": { "newRoot": "$data" } },
{ "$lookup": { "from": "profile", "localField": "profile_id", "foreignField": "_id", "as": "profile_data" } },
{ "$unwind": { "path": "$profile_data" } },
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_data.profile_recommendation_info_id", "foreignField": "_id", "as": "lifeband_info" } },
{ "$unwind": { "path": "$lifeband_info" } },
{ "$addFields": { "category_value": { "$abs": { "$subtract": [{ "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.max" }, { "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.min" }] } } } },
{ "$unset": ["last_modified_data", "notification_type", "progress_status", "lifeband_info", "profile_data"] }]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" }, { "$replaceRoot": { "newRoot": "$data" } },
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_id", "foreignField": "profile_id", "as": "lifeband_info" } },
{
"$project": {
"profile_id": 1,
"lifeband_info": { "$arrayElemAt": ["$lifeband_info", 0] }
}
},
{ "$addFields": { "category_value": { "$abs": { "$subtract": [{ "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.max" }, { "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.min" }] } } } },
{
"$project": {
"profile_id": 1,
"category_value": 1
}
},
{ "$lookup": { "from": "profile_event", "localField": "profile_id", "foreignField": "profile_id", "as": "profile_event_data" } },
{
"$project": {
"profile_id": 1, "category_value": 1,
"event_type_set": { "$concatArrays": ["$profile_event_data.event_type"] }
}
},
{
"$project": {
"profile_id": 1, "category_value": 1,
"event_exists": { "$in": ["JUVBAND_ACCURACY_MEDIUM_NX", "$event_type_set"] }
}
},
{ "$match": { "event_exists": { "$ne": true } } },
{
"$addFields": {
"_id": { "$concat": ["JUVBAND_ACCURACY_MEDIUM_0X:", "$profile_id"] },
"event_type": "JUVBAND_ACCURACY_MEDIUM_NX", "event_trigger_date": "$$NOW", "event_occurence": 0, "trigger_status": "SILENT"
}
},
{ "$unset": "event_exists" }]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$match": { "event_type": { "$eq": "JUVBAND_ACCURACY_MEDIUM_NX" } } },
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" }, { "$replaceRoot": { "newRoot": "$data" } },
{ "$lookup": { "from": "profile", "localField": "profile_id", "foreignField": "_id", "as": "profile_data" } },
{ "$unwind": { "path": "$profile_data" } },
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_data.profile_recommendation_info_id", "foreignField": "_id", "as": "lifeband_info" } },
{ "$unwind": { "path": "$lifeband_info" } },
{
"$addFields": {
"category_value": { "$abs": { "$subtract": [{ "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.max" }, { "$toDouble": "$lifeband_info.output.lifeband.accuracyLevel.min" }] } }
}
},
{ "$unset": ["last_modified_date", "notification_type", "progress_status", "lifeband_info", "profile_data", "accuracy_level"] }
]
}
},
{
"$unionWith": {
"coll": "profile_event", "pipeline": [
{ "$sort": { "event_trigger_date": -1 } },
{ "$group": { "_id": { "profile_id": "$profile_id" }, "data": { "$first": "$$ROOT" } } },
{ "$unset": "_id" }, { "$replaceRoot": { "newRoot": "$data" } },
{ "$addFields": { "profile_strength_id": { "$concat": ["profile_strength:", "$profile_id"] } } },
{ "$lookup": { "from": "profile_event", "localField": "profile_strength_id", "foreignField": "_id", "as": "profile_strength_info" } },
{ "$unwind": { "path": "$profile_strength_info" } }, { "$addFields": { "category_value": { "$toInt": "$profile_strength_info.progress_status" } } },
{ "$project": { "profile_id": 1, "category_value": 1 } },
{ "$lookup": { "from": "profile_event", "localField": "profile_id", "foreignField": "profile_id", "as": "profile_event_data" } },
{
"$project": {
"profile_id": 1,
"category_value": 1,
"event_type_set": { "$concatArrays": ["$profile_event_data.event_type"] }
}
},
{
"$project": {
"profile_id": 1,
"category_value": 1,
"event_exists": { "$in": ["PROFILE_MEDIUM_NX", "$event_type_set"] }
}
},
{ "$match": { "event_exists": { "$ne": true } } },
{
"$addFields": {
"_id": { "$concat": ["PROFILE_MEDIUM_0X:", "$profile_id"] },
"event_type": "PROFILE_MEDIUM_NX",
"event_occurence": 0,
"trigger_status": "SILENT"
}
},
{ "$unset": "event_exists" },
{
"$project": {
"event_type": 1,
"profile_id": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"trigger_status": 1,
"category_value": { "$cond": { "if": { "$eq": ["$category_value", null] }, "then": 0, "else": "$category_value" } }
}
},
{ "$lookup": { "from": "profile_lifeband_info", "localField": "profile_id", "foreignField": "profile_id", "as": "lifeband_info" } },
{
"$project": {
"event_type": 1,
"profile_id": 1,
"event_trigger_date": 1,
"event_occurence": 1,
"lifeband": 1,
"trigger_status": 1,
"category_value": 1,
"lifeband_info": { "$arrayElemAt": ["$lifeband_info", 0] }
}
},
{
"$addFields": {
"event_trigger_date": "$lifeband_info.created_date"
}
},
{ "$unset": "lifeband_info" }
]
}
}
])
问题内容: 在PostgreSQL 8.4中,我想从3个ID为ID的表中创建一个视图。因此,我想采用以下结构: 我可以选择,并从表: 如何在视图中创建列? 更新 我找到了解决方案: 但我不知道如何在中使用它。我怎么把它放在那里? 问题答案: 您不能使用删除或添加列。我引用ALTER VIEW上的手册 : 更改视图的各种辅助属性。(如果要修改视图的定义查询,请使用。) 但是一个简单的方法并不能解决问
我有一个 TableView,它的内容应该是可编辑的,实际上必须保留在数据库中。此表视图有一些预定义的列和其他一些将在运行时定义的列。假设我的表格将显示一些特殊食物的主要材料。这些主要材料具有一些预定义的列(属性),例如名称、价格和单位;此外,这些主要材料还有一些其他属性,这些属性根据以前的用户输入(如脂肪、蛋白质等)保留在数据库中。请注意,这些属性位于数据库中,应在运行时映射到表中的列(这些列也
我在Google和Stackoverflow上搜索过这个,但我只是没有得到给定的示例。有人能给我解释一下吗? 我想在表视图的最后一列添加一个按钮,当它被单击时,它应该触发一个侦听器并传递buttons行的对象。我只是没有从gist中得到下面的例子。github。通用域名格式: 这是我的完整当前代码: 现在,我必须创建一个的部分是可以理解的。但是如何将其分配给列呢? 我明白这一点: 但不是这个:
我试图在android中创建一个具有圆形边缘的视图。到目前为止,我找到的解决方案是定义一个具有圆角的形状,并将其用作该视图的背景。 下面是我所做的,定义一个可绘制的,如下所示: 现在我用它作为我的布局背景,如下所示: 这工作非常好,我可以看到视图有圆形的边缘。 但是我的布局中有许多其他的子视图,比如ImageView或MapView。当我在上面的布局中放置时,图像的角落不会被裁剪/裁剪,而是显示为
我不知道这是否是搜索“在子视图中添加UIViewController”的正确键。正如您在我的图像中看到的,有两个ViewController,主控制器和第二个控制器。主控制器内部有一个UIView(蓝色背景色)。在UIView中,我想在UIView中添加第二个ViewController。我有这个代码,但不起作用。 这是我的密码 我想知道这是否可行?我知道在xib文件中工作,我不知道在google
问题内容: 我已经在Google和Stackoverflow上进行了搜索,但没有得到给出的示例。有人可以向我解释一下。 我想在表视图的最后一列中添加一个按钮,当单击它时,它应该触发一个侦听器并传递按钮行的对象。我只是没有从 gist.github.com 得到以下示例: 这是我目前的完整代码: 现在我必须创建的部分是可以理解的。但是如何将其分配给列? 我了解这一点: 但这不是: 问题答案: 为了能