You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
script like "const avgSendReceiveDiff = db.chatGptMessage.aggregate([
{
$project: {
created_by: 1,
timeDifference: { $subtract: ["$receive_time", "$send_time"] }
}
},
{
$group: {
_id: "$created_by",
avgTimeDifference: { $avg: "$timeDifference" }
}
}
])"
When i use context.eval("js",script)
I expected the "$subtract: ["$receive_time", "$send_time"]" stay unchanged and mongo java driver can parse, but when i extract the string, it was serialize into " $subtract: Array(2)", and mongodb can not parse.
How can i fix this?
The text was updated successfully, but these errors were encountered:
I suppose you got that from Value.toString()? That string representation is not supposed to be consumed by applications. You can use various Value methods (like getMember(), getMemberKeys(), getArrayElement(), getArraySize()) to access object members and array elements, or use JSON.stringify to convert an object back into a string.
script like "const avgSendReceiveDiff = db.chatGptMessage.aggregate([
{
$project: {
created_by: 1,
timeDifference: { $subtract: ["$receive_time", "$send_time"] }
}
},
{
$group: {
_id: "$created_by",
avgTimeDifference: { $avg: "$timeDifference" }
}
}
])"
When i use context.eval("js",script)
I expected the "$subtract: ["$receive_time", "$send_time"]" stay unchanged and mongo java driver can parse, but when i extract the string, it was serialize into " $subtract: Array(2)", and mongodb can not parse.
How can i fix this?
The text was updated successfully, but these errors were encountered: