jjzjj

mongodb-shell

全部标签

mongodb - 如何修复 : Golang "append" method pushing same elements to slice

我正在尝试将数据从DB(Mongo)映射到sliceingo,如果我返回简单的[]string一切正常,但如果我将类型更改为[]*models.Organization代码返回相同元素的slice。func(os*OrganizationService)GetAll()([]*models.Organization,error){varorganizations[]*models.Organizationresults:=os.MongoClient.Collection("organizations").Find(bson.M{})organization:=&models.Orga

shell - 将 shell 输出转换为 float64?

我正在使用带有golang的shell来访问apache日志文件并获取一些数据。首先,我曾经直接将输出写入文件并且它可以正常工作,但现在我需要获取输出并直接在程序中使用它。而且我还需要将它转换为float64。我尝试将其转换为字符串,然后再转换为float64,但它不起作用?funcMem_usage_data(jint)(Mem_predictfloat64,errerror){awkPart:=fmt.Sprintf("awk'{print$%d/1024}'",j)out1,err:=exec.Command("bash","-c","tail-n1/var/log/apache

database - 在 Go 中以及可能在其他语言和其他数据库中比较 mongodb 驱动程序的时间精度问题

我正在学习Go和Mongodb,目前正在使用alphaofficialmongodbdriver.虽然它处于alpha阶段,但我认为它对于基本用法来说非常实用。但是我在这个数据库驱动程序中遇到了一个关于时间转换的有趣问题。基本上,我创建了一个自定义类型的结构对象,并将其编码为bson文档,然后将bson文档转换回结构对象。//checkgithub.com/mongodb/mongo-go-driver/blob/master/bson/marshal_test.gofuncTestUserStructToBsonAndBackwards(t*testing.T){u:=user{Us

go - 将 `go` 与 fish shell 一起使用

我正在努力在fishshell中运行go。A)我遵循了安装过程并按照documentation中的说明安装了go但是,当我运行goversion时,出现fatalerror:fatal:notagitrepository(oranyparentuptomountpoint/)Stoppingatfilesystemboundary(GIT_DISCOVERY_ACROSS_FILESYSTEMnotset).当我通过gitinit初始化git时,我收到另一个错误:error:pathspec'version'didnotmatchanyfile(s)knowntogit我在我的fish

mongodb - 当我运行 docker compose 时,我的 golang(摄取)容器无法显示 "Error establishing Mongo session"

我运行了一个docker-composeup,我在我的golang容器上收到一条错误消息,提示“ErrorestablishingMongosession”,然后容器退出。我不确定问题是否始于我的golang容器或mongo。此时我已经尝试了很多事情。这是我的golang容器的docker日志文件。golang的docker日志Torunindebugmode,runwith'-dtrue'optiontime="2019-08-20T20:12:12Z"level=infomsg="LogginginINFOmode"time="2019-08-20T20:12:12Z"level=

mongodb - 在golang mgo中让字段空白

我正在尝试将beego与mongo结合使用。你可以在以下位置找到我的来源:https://github.com/wsourabh/bapi但是在调用v1/账户/:id我总是得到这样的回应curl-vlocalhost:8080/v1/accounts/0df542560fbfc39a4bdb24d0ca44d37e*Trying127.0.0.1...*Connectedtolocalhost(127.0.0.1)port8080(#0)>GET/v1/accounts/0df542560fbfc39a4bdb24d0ca44d37eHTTP/1.1>Host:localhost:80

mongodb - 访问 map 时的 Goroutine block

以下代码片段取自旨在从MongoDB读取文档并将其写入Postgres数据库的程序。该程序是使用生产者/消费者模式实现的:生产者Goroutine从Mongo读取并将获取的文档发送到channel。consumerGoroutine从channel中读取数据,构造一个INSERTINTOsql语句并将数据插入到Postgres数据库中。不幸的是,消费者似乎不确定地阻止。我相信当访问从producer到consumer的chan传递的map数据结构时,就会发生这种情况,但不能确定。生产者的简化代码:funcproducer(opschanBatchOp,...){//Iterateove

mongodb - 有没有办法通过 Find() 获取 slice ?

现在我在做:sess:=mongodb.DB("mybase").C("mycollection")varusers[]struct{Usernamestring`bson:"username"`}err=sess.Find(nil).Select(bson.M{"username":1,"_id":0}).All(&users)iferr!=nil{fmt.Println(err)}varmyUsers[]stringfor_,user:=rangeusers{myUsers=append(myUsers,user.Username)}有没有更有效的方法直接从Find(或其他搜索函数

shell - 如何使用 Go 程序中的点脚本运行 graphviz 进程?

我想运行一个输出到图像的点脚本。我如何从Golang调用它?packagemainimport("fmt""os/exec")funcmain(){path,err:=exec.LookPath("dot")cmd:=exec.Command(path,"-Tpng","/Users/arafat/Desktop/dev/go/src/github.com/Arafatk/dataviz/DotExamples/arraylist.dot",">","/Users/arafat/Desktop/dev/go/src/github.com/Arafatk/dataviz/hello.pn

mongodb - 如何编码/解码 mongodb 游标?

我需要建立一个“页面”列表,所以其中一部分会有一个cursor.问题是我找不到编码(到字符串)和解码光标的方法。任何的想法?Cursor接口(interface)没有“编码”方法(有ID,但未记录)并且无法从字符串(或int)创建新游标。typeCursorinterface{//GettheIDofthecursor.ID()int64//Getthenextresultfromthecursor.//Returnstrueiftherewerenoerrorsandthereisanextresult.Next(context.Context)boolDecode(interfac