-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed as not planned
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid
Description
I'd like to translate following MongoDB query into Spring Data MongoDB(and QueryDSL if needed).
Does Spring Data MongoDB support this kind of query?
I've already asked this on stackoverflow, but I couldn't get any answer.
db.user_history.findOneAndUpdate(
{ userId: 23022569 },
[
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{ "userId": 23022569, "history": [], "autoIncrement": 0 },
"$$ROOT"
]
}
}
},
{
$set: {
history: {
$cond: {
if: { $gt: [{ $size: "$history" }, 50] },
then: "$history",
else: {
$concatArrays: [
"$history",
[{
"_id": new ObjectId(),
"sequence": { $add: ["$autoIncrement", 1] },
"lastViewedAt": new Date(),
"createdAt": new Date(),
}]
]
}
}
},
autoIncrement: { $add: ["$autoIncrement", 1] }
}
}
],
{
returnNewDocument: true,
upsert: true
}
);A format of the user_history collection would be like this.
[
{
"user_id": 1,
"history": [
{
"_id": new ObjectId("(random hex string)"),
"sequence": 0,
"lastViewedAt": new Date(),
"createdAt": new Date(),
}
],
"auto_increment": 1,
}
]Metadata
Metadata
Assignees
Labels
status: invalidAn issue that we don't feel is validAn issue that we don't feel is valid