I'm trying to add a json map to an array in my database using monger
but there is something wrong. I've found how to do it in monger documentation, but $push
and $addToSet
aren't working:
Here is my function:
(defn add-vehicle [vehicle]
(let [connect-string (System/getenv "MONGO_CONNECTION")
{:keys [conn db]} (mg/connect-via-uri connect-string)]
(mc/update db "drivers-collection"
{:email (:email vehicle)}
{$addToSet {:cars (:vehicle vehicle)}})))
And this is how I'm calling this function in nREPL
:
(add-vehicle {:email "teste111@hotmail.com"
:vehicle {:model "fusca"
:color "rosa"
:plate "AIO-9807"}})
Any ideas?
EDIT
This is my document in drivers-collection
:
{
"_id": {
"$oid": "57bee61edcba0f2f7559eb56"
},
"email": "teste111@hotmail.com",
"name": "Guilherme Job",
"cars": [],
"customerId": "cus_9O4dhvtuF2926m"
}
My car's array are empty and I'm trying to add a vehicle into it.