I'mtryingtocheckacollectiontoseeifthereisatleastonedocumentsthatmatchaspecificsetofvalues.
HereisasamplequeryfromStudio3TthatI'mtryingtorunwithmongo-go-driver:
db.getCollection("events").find({"event.eventType":"OSR","context.vehicleId":NumberInt(919514),"ts":{"$gte":ISODate("2019-06-21T21:38:43.022+0000")}}).limit(1);Itseemsthatthecontext.FindOnemethodwilldowhatIwant(andeliminatingtheneedforthe.limit(1)).Ithoughtthatitwouldbestraightforwardto"port"thistoGoandthemongo-go-driver.
Icansortofmakethiswork,forexampleIhavethefollowingwhichwillfindmealltheOSR:
varquery=&bson.D{{"event.eventType","OSR"},}result:=bson.D{}e:=collection.FindOne(context.TODO(),query).Decode(&result)Thiswillreturnmeonedocument.Now,ifIwanttoincludethevehicleIdvalue,andIupdatethequeryto:
varquery=&bson.D{{"event.eventType","OSR"},{"context.vehicleId",919514},}Nodocumentsarereturned.Ihaven'tbothertoexpandquerytoincludethetsfieldyet.
Iwouldexpectattostillhaveatleastonedocumentreturned,butnothingisshowingup.Doesanybodyhavesometips,suggestionsorguidanceonwhatI'mdoingwrong(orperhapshowIcandothisbetter)
当前问题酬金
¥0(可追加¥500)
支付方式
扫码支付
支付金额15元
提供问题酬金的用户不参与问题酬金结算和分配
Notquitesure,buthaveyoutriedwithbson.Minsteadofbson.D
Itseemslikeit'sworkingformeatleast.
Also,like@owlwalkssaid,areyousure,you'reintherightcollection