Database
[{y:4},{y:5},{y:5},{y:7},{y:9},{y:14},{y:15},{y:20},{y:22}]
Query
db.collection.aggregate([{$setWindowFields:{partitionBy:"",sortBy:{y:1},output:{previous:{$push:"$y",window:{range:[-3,0]}}}}},{"$set":{"previous":{"$cond":{"if":{"$gt":[{"$size":"$previous"},1]},"then":{"$first":"$previous"},"else":null}}}}])