Thursday, 15 March 2012

go - Sequential queries with golang & mongodb -



go - Sequential queries with golang & mongodb -

wondering best way create sequential queries golang mongodb. illustration lets have :

result *bson.m ids:=["543d171c5b2c12420dd016","543d171c5b2dd016"] oids := make([]bson.objectid, len(ids)) := range ids { oids[i] = bson.objectidhex(ids[i]) } query := bson.m{"_id": bson.m{"$in": oids}} error:= c.find(query).all(&result)

and want take output of _ids , utilize query table. correct?

query = bson.m{"_id": bson.m{"$in": result}}

here's how build query using ids of documents returned other query.

var docs []bson.m if err := c.find(query).all(&docs); err != nil { // handle error } docids := make([]interface{}, len(docs)) := range docs { docids[i] = docs[i]["_id"] } query = bson.m{"_id": bson.m{"$in": docids}}

mongodb go sequential

No comments:

Post a Comment