I can't understand how to properly use $literal. I am using mgo.v2 and mgo.v2/bson package.
db.store.aggregate([
{"$project":{
"location":{
"type":{"$literal":"Point"},
"coordinates":["$longitude","$latitude"]
}}
},])
I used the above code to fetch data in mongodb and working fine.It gives me the result
{ "location":{
"type":"Point",
"coordinates":[77.587073,12.958794]
}}
I tried to use the same in golang and it is shown below
pipe :=DB.C("store").Pipe([]bson.M{
{"$project":bson.M{"location":
bson.M{"type":
bson.M{"$literal":"Point"},"coordinates":[]interface{}{"$longitude","$latitude"}}}}}
Above code, throws me an error
panic: bad query: BadValue: Point must be an array or object
so I replaced it like this
pipe :=DB.C("store").Pipe([]bson.M{
{"$project":bson.M{"location":
bson.M{"$literal":
bson.M{"type":"Point"},"coordinates":[]interface{}{"$longitude","$latitude"}}}}})
but this also throws me an error
panic: this object is already an operator expression, and can't be used as a document expression (at 'coordinates')
my complete work is shown in the below link my work is here please help me to solve this. Thank you