#How to get _id as slice from returned cursor after find() function Golang & mongoDB

8 messages · Page 1 of 1 (latest)

vale forge
#

Hi guys, as the title, i am trying use _id from result that returned from find() query to continue searching data in other collection.
I try to get all _id from result, append them into slice []primitive.ObjectID but it's not work.

Can you guys help me? gophercrying

limber current
vale forge
#

i think problem is

append(roomIDs, bson.ObjectIdHex(restricstion["room_id"]))
bson.ObjectIdHex(restricstion["room_id"]) -> this method does'nt return type primitive.ObjectID. How can i get _id with type primitive.ObjectID from cursor 😦

limber current
#

bson.M is alias to map[string]interface{}
You need to cast it. i'll be trial and error it could be either string or already a primitive.ObjectID

limber current
#

restriction["room_id"].(primitive.ObjectID)

vale forge
#

thank you
i tried with this but it's still not work 😢

limber current
#

Have you done the tour?
roomIDs = append(roomIDs, value)

vale forge