Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do a like query using mgo package for golang

I am trying to do a like query using mgo with no luck.

what I want is a mongodb query similar to

db.organisation.find( { "permalink" : /org.*/ } )

I am still stuck at

sess.DB(db).C(cApp).
    Find(bson.M{"permalink": "org:bms.*"}).
    All(&m)
like image 668
Sumit M Asok Avatar asked Jan 31 '15 23:01

Sumit M Asok


1 Answers

Use bson.Regex to specify a regular expression value:

sess
  .DB(db)
  .C(cApp)
  .Find(bson.M{"permalink": bson.RegEx{"org.*", ""}})
  .All(&m)
like image 67
Bayta Darell Avatar answered Nov 09 '22 04:11

Bayta Darell