how do i add a value to the top of an array in mongodb?
say i have this document in my mongo collection:
{ "colors" : [ "red", "green", "blue" ] }
how do i add "yellow" to the front of the list?
when i do:
{$push:{colors:"yellow"}}
i'd get this:
{ "colors" : [ "red", "green", "blue", "yellow" ] }
i want this:
{ "colors" : [ "yellow", "red", "green", "blue"] }
thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…