This is a creation in Article, where the information may have evolved or changed.
Today by the MgO ferocious grammar toss on the ground for 1 hours to get out hereby commemorate:
Generally do a simple query, is written like this:
<pre name= "code" class= "plain" >collection: = Mgodbcontroller. Getmdb (). C (Mgodbcontroller. User_wallet_gs_log)//Get Action Object
According to the user's mobile phone number in reverse query First 100 deposit slice if err: = collection. Find (&bson. m{"Uphone": Phonenum}). Sort ("-initimesamp"). Limit (100). All (&historys); Err = = Nil {For I, _: = Range Historys {fmt. PRINTLN ("Data from MgO--->", historys[i]) ms = Append (MS, &historys[i])}} else {fmt. PRINTLN ("Query history", err) Logutils.getlog (). Error ("Query history", err)}
Now need to query these users, mobile phone number is 18112345678, while historical information is Reasona or REASONB history, if directly with the command to query, it is very simple, so write good:
Db.userwalletgslog.find ({"Uphone": "18112345678", "Reason": {"$in": ["Reasona", "Reasonb"]})
Next, the problem of bitterness, to use the Golang call MgO to achieve the above statement, the whole
Baidu N Long, find a so write: (link is http://blog.csdn.net/varding/article/details/17200299)
C.find (Bson. m{"name": Bson. m{"$in": []string{"Jimmy Kuu", "Tracy Yu"}}). All (&users)
His writing is actually a bit of a problem, at least my program is not run up, after a long ~~~~~~ time test, here 's the answer:
ERR: = collection. Find (&bson. m{"Uphone": "18112345678", "Reason": &bson. m{"$in": []string{"Reasona", "Reasonb"}}}). All (&historys)
See, see, this pit father's &bson. M I really mean it.