用mongo-connector同步mongodb和elasticsearch遇到的几个问题

我希望把mongodb中存储的数据同步到elasticsearch,以便后续实现检索功能。系统是windows10,各种工具和环境都搭建好了,mongodb的副本集也已建立,elasticsearch版本是6.X,同步工具选择的是mongo-connector,同步命令如下:

mongo-connector --auto-commit-interval=0 -m localhost:27017 -t localhost:9200 -d elastic2_doc_manager -o mongodb_oplog_position.oplog

但是在数据同步过程中遇到了几个问题:
1.
failed to parse field [xx] of type [long]
出错的数据是一个32位的MD5值,在mongodb中的数据类型是String,是因为长度太长了所以出这个错误吗,该怎么解决呢?

2.
Rejecting mapping update to [db] as the final mapping would have more than 1 type: [t1, t2]
提示一个index中不能有多个type,查了一下,发现是elasticsearch 6.X版本以后的新规范,但是mongodb通常会一个DB中有多个Collection,这个该怎么同步呢?

请各位大佬帮忙解答一下。

1个回答

1.第一个问题
32位MD5的值,每一个都是16进制数,而java中long是十进制的数,所以只要你的字符串中带有十六进制的字母abcdef,就会报错,推荐你在传输之前,解密一下,再存储,或者指定es字段类型为string
2.第二个问题
ES中某个资源的定位是这样的形式的
host:port/index/type/id
ES6之后,只能有一个type,以后可能移除这个,所以现在如果是多个type的话,可以把index和type名拼接。
host:port/index_type/xxx/id这样的形式

u014755796
白小丸 回复monkey06: 最后我放弃使用es了...
大约一年之前 回复
monkey06
monkey06 回复白小丸: 请问这个问题有什么解决办法吗?
大约一年之前 回复
u014755796
白小丸 回复哈喽大海豚: 多谢啦
大约一年之前 回复
weixin_29444181
哈喽大海豚 回复白小丸: 好像是要更改源代码,不知道配置的时候能不能指定type,你可以看看mongo-connector的文档,或者看看最新的mongo-connector有没有对应es6.x
大约一年之前 回复
u014755796
白小丸 您好,您说的指定es字段类型和host:port/index_type/xxx/id,这些是要修改mongo-connector源码或者自己写脚本同步吗?我现在只会用一条命令行语句同步,不知道这些在哪里进行设置。
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
mongo-connector集成启动报错

mongo-connector启动命令: service mongo-connector start 然后报错: ![图片说明](https://img-ask.csdn.net/upload/201611/23/1479882609_290410.jpg) 在linux环境下面,好像是mongo-connector脚本命令43行有问题,请教高人如何解决!

您如何使用官方的mongo-go-driver连接到MongoDB Atlas [重复]

<div class="post-text" itemprop="text"> <div class="question-status question-originals-of-duplicate"> <p>This question already has an answer here:</p> <ul> <li> <a href="/questions/52052311/how-to-use-new-url-from-mongodb-3-6-to-connect-from-golang" dir="ltr">How to use new URL from mongodb 3.6 to connect from golang</a> <span class="question-originals-answer-count"> 1 answer </span> </li> </ul> </div> <p>I'm looking at the <a href="https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial-part-1-connecting-using-bson-and-crud-operations" rel="nofollow noreferrer">tutorial</a> offered in conjunction with the release of the official <a href="https://github.com/mongodb/mongo-go-driver" rel="nofollow noreferrer">mongo-go-driver</a> and the connection example uses a MongoDB server on <code>localhost</code></p> <pre><code>// Set client options clientOptions := options.Client().ApplyURI("mongodb://localhost:27017") </code></pre> <p>However, the new hosted MongoDB service <a href="https://www.mongodb.com/cloud/atlas" rel="nofollow noreferrer">Atlas</a> requires username and password to login. The connection string takes the format </p> <pre><code>mongodb://[username:password@]host1[/[database][?options]] </code></pre> <p>but there is no Golang example in the <a href="https://docs.atlas.mongodb.com/driver-connection/#driver-examples" rel="nofollow noreferrer">driver examples for Atlas</a>.</p> <p>So I'm wondering, what is the best way to log into Atlas without hard coding a password into a source file that will be posted on Github?</p> </div>

通过mongo-go-driver连接mongodb会消耗大量内存

<div class="post-text" itemprop="text"> <p>I'm using mongo-go-driver, parallel connect several ports to check whether the port is listened by mongodb </p> <p>go version 1.12.3 mongo-go-driver v1.0</p> <pre class="lang-golang prettyprint-override"><code>type BaseServerStatus struct { Host string `bson:"host"` Version string `bson:"version"` Process string `bson:"process"` Pid int64 `bson:"pid"` Uptime int64 `bson:"uptime"` UptimeMillis int64 `bson:"uptimeMillis"` UptimeEstimate int64 `bson:"uptimeEstimate"` LocalTime time.Time `bson:"localTime"` } func GetBaseServerStatus(ip, port string) (srvStatus *BaseServerStatus, err error) { opts := options.Client() opts.SetDirect(true) opts.SetServerSelectionTimeout(1 * time.Second) opts.SetConnectTimeout(2 * time.Second) opts.SetSocketTimeout(2 * time.Second) opts.SetMaxConnIdleTime(1 * time.Second) opts.SetMaxPoolSize(1) url := fmt.Sprintf("mongodb://%s:%s/admin", ip, port) opts.ApplyURI(url) ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) conn, err := mongo.Connect(ctx, opts) if err != nil { fmt.Printf("new %s:%s mongo connection error: %v ", ip, port, err) return } defer conn.Disconnect(ctx) err = conn.Ping(ctx, nil) if err != nil { fmt.Printf("ping %s:%s ping error: %v ", ip, port, err) return } sr := conn.Database("admin").RunCommand(ctx, bson.D{{"serverStatus", 1}}) if sr.Err() != nil { fmt.Printf("get %s:%s server status error: %v ", ip, port, sr.Err()) return } srvStatus = new(BaseServerStatus) err = sr.Decode(srvStatus) return } func main() { var wg sync.WaitGroup //ips := []string{"xxx.xxx.xxx.xxx:22"} ips := []string{"xxx.xxx.xxx.xxx:22", "xxx.xxx.xxx.xxx:80", "xxx.xxx.xxx.xxx:7005", "xxx.xxx.xxx.xxx:7017", "xxx.xxx.xxx.xxx:7006", "xxx.xxx.xxx.xxx:7016", "xxx.xxx.xxx.xxx:7018", "xxx.xxx.xxx.xxx:7014", "xxx.xxx.xxx.xxx:199", "xxx.xxx.xxx.xxx:8182", "xxx.xxx.xxx.xxx:7015", "xxx.xxx.xxx.xxx:7022", "xxx.xxx.xxx.xxx:7013", "xxx.xxx.xxx.xxx:7020", "xxx.xxx.xxx.xxx:9009", "xxx.xxx.xxx.xxx:7004", "xxx.xxx.xxx.xxx:7008", "xxx.xxx.xxx.xxx:7002", "xxx.xxx.xxx.xxx:7021", "xxx.xxx.xxx.xxx:7007", "xxx.xxx.xxx.xxx:7024", "xxx.xxx.xxx.xxx:7010", "xxx.xxx.xxx.xxx:7011", "xxx.xxx.xxx.xxx:7003", "xxx.xxx.xxx.xxx:7012", "xxx.xxx.xxx.xxx:7009", "xxx.xxx.xxx.xxx:7019", "xxx.xxx.xxx.xxx:8001", "xxx.xxx.xxx.xxx:7023", "xxx.xxx.xxx.xxx:111", "xxx.xxx.xxx.xxx:7001", "xxx.xxx.xxx.xxx:8002", "xxx.xxx.xxx.xxx:19313", "xxx.xxx.xxx.xxx:15772", "xxx.xxx.xxx.xxx:19777", "xxx.xxx.xxx.xxx:15778", "xxx.xxx.xxx.xxx:15776"} for _, ip := range ips { wg.Add(1) //time.Sleep(3 * time.Second) go func(addr string) { fmt.Printf("start to probe port %s ", addr) GetBaseServerStatus(strings.Split(addr, ":")[0], strings.Split(addr, ":")[1]) wg.Done() }(ip) } wg.Wait() fmt.Println("scan end") time.Sleep(20 * time.Second) } </code></pre> <p>however, run this code ,it consume 26GB memory I use pprof to diagnose, see below</p> <p>Showing top 10 nodes out of 15 flat flat% sum% cum cum% 26.29GB 96.86% 96.86% 26.29GB 96.86% go.mongodb.org/mongo-driver/x/network/connection.(*connection).ReadWireMessage</p> </div>

如何使用golang和mongo-go-driver在mongodb中创建文本索引?

<div class="post-text" itemprop="text"> <p>I'm trying to do a full text search on a collection, but in order to do that I need to create a text index. How can I create a text index on two fields?</p> <p>I know that I must use a thing as this:</p> <pre><code>opts := options.CreateIndexes().SetMaxTime(10 * time.Second) idxFiles := []mongo.IndexModel{ { Keys: bsonx.Doc{{"name": "text"}}, }, } db.Collection("mycollection").Indexes().CreateMany(context, idx, opts) </code></pre> </div>

如何使用mongodb / mongo-go-driver执行有效的分页

<div class="post-text" itemprop="text"> <p>I read in the following article that it is more efficient to use the natural ordering of <code>_id</code> to perform paging because skip always starts from the beginning from the collection</p> <p><a href="https://www.codementor.io/arpitbhayani/fast-and-efficient-pagination-in-mongodb-9095flbqr" rel="nofollow noreferrer">https://www.codementor.io/arpitbhayani/fast-and-efficient-pagination-in-mongodb-9095flbqr</a> </p> <pre><code>// Page 1 db.students.find().limit(10) // Page 2 last_id = ... # logic to get last_id db.students.find({'_id': {'$gt': last_id}}).limit(10) </code></pre> <p>But I have no idea how to perform the above using the <code>mongodb/mongo-go-driver</code>.</p> </div>

如何使用mongo-go-driver有效地将bson转换为json?

<div class="post-text" itemprop="text"> <p>I want to convert bson in <a href="https://github.com/mongodb/mongo-go-driver" rel="nofollow noreferrer">mongo-go-driver</a> to json effectively.</p> <p>I should take care to handle <code>NaN</code>, because <code>json.Marshal</code> fail if <code>NaN</code> exists in data.</p> <p>For instance, I want to convert below bson data to json.</p> <pre class="lang-golang prettyprint-override"><code>b, _ := bson.Marshal(bson.M{"a": []interface{}{math.NaN(), 0, 1}}) // How to convert b to json? </code></pre> <p>The below fails.</p> <pre class="lang-golang prettyprint-override"><code>// decode var decodedBson bson.M bson.Unmarshal(b, &amp;decodedBson) _, err := json.Marshal(decodedBson) if err != nil { panic(err) // it will be invoked // panic: json: unsupported value: NaN } </code></pre> </div>

Mongo-Go-Driver无法连接

<div class="post-text" itemprop="text"> <p>So I am trying to use <a href="https://github.com/mongodb/mongo-go-driver" rel="nofollow noreferrer">https://github.com/mongodb/mongo-go-driver</a> to connect to a mongo database in golang.</p> <p>Here is my connection handler: </p> <pre><code>var DB *mongo.Database func CreateConnectionHandler()(*mongo.Database, error){ fmt.Println("inside createConnection in database package") godotenv.Load() fmt.Println("in CreateConnectionHandler and SERVER_CONFIG: ") fmt.Println(os.Getenv("SERVER_CONFIG")) uri:="" if os.Getenv("SERVER_CONFIG")=="kubernetes"{ fmt.Println("inside kubernetes db config") uri = "mongodb://patientplatypus:SUPERSECRETPASSDOOT@ mongo-release-mongodb.default.svc.cluster.local:27017/ platypusNEST?authMechanism=SCRAM-SHA-1" }else if os.Getenv("SERVER_CONFIG")=="compose"{ fmt.Println("inside compose db config") uri = "mongodb://datastore:27017" } ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) client, err := mongo.Connect(ctx, uri) if err != nil { return nil, fmt.Errorf("mongo client couldn't connect: %v", err) } DB := client.Database("platypusNEST") return DB, nil } </code></pre> <p>And the error I am getting: </p> <pre><code>api | database/connection.go:29:30: cannot use uri (type string) as type *options.ClientOptions in argument to mongo.Connect </code></pre> <p>So I tried replacing <code>uri</code> with the connection string like this: </p> <pre><code>client, err := mongo.Connect(ctx, "mongodb://datastore:27017") </code></pre> <p>But I still got the error.</p> <p>Compare this with what is in the documentation: </p> <blockquote> <pre><code>ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) client, err := mongo.Connect(ctx, "mongodb://localhost:27017") </code></pre> </blockquote> <p>And it is exactly the same! I'm really not sure why there is this error. Any ideas?</p> </div>

去Dockerfile中的mongo-go-driver崩溃

<div class="post-text" itemprop="text"> <p>I have a little problem with my Go service. I'm new to Go and I just want to dockerize a little service that just connect to a mongodb instance.</p> <p>My code works fine locally. So here is my Dockerfile:</p> <pre><code># build stage FROM golang:alpine AS build-env RUN apk add --no-cache git ADD . . RUN go get -v -u go.mongodb.org/mongo-driver RUN go build -o mongotest # final stage FROM alpine WORKDIR /app COPY --from=build-env ./go/mongotest . RUN apk update &amp;&amp; apk add ca-certificates &amp;&amp; rm -rf /var/cache/apk/* EXPOSE 8000 CMD ["./mongotest"] </code></pre> <p>When I build it, I have this error message :</p> <pre class="lang-none prettyprint-override"><code>Step 6/18 : RUN go get -v -u go.mongodb.org/mongo-driver ---&gt; Running in 4c45c601800d Fetching https://go.mongodb.org/mongo-driver?go-get=1 Parsing meta tags from https://go.mongodb.org/mongo-driver?go-get=1 (status code 200) get "go.mongodb.org/mongo-driver": found meta tag get.metaImport{Prefix:"go.mongodb.org/mongo-driver", VCS:"git", RepoRoot:"https://github.com/mongodb/mongo-go-driver.git"} at https://go.mongodb.org/mongo-driver?go-get=1 go.mongodb.org/mongo-driver (download) package go.mongodb.org/mongo-driver: no Go files in /go/src/go.mongodb.org/mongo-driver The command '/bin/sh -c go get -v -u go.mongodb.org/mongo-driver' returned a non-zero code: 1 </code></pre> <p><code>no Go files in /go/src</code> ... ok, what can I do with that?</p> <p>The strange thing is that if I replace </p> <p><code>RUN go get -d -u go.mongodb.org/mongo-driver</code></p> <p>by </p> <p><code>RUN go get -d -u github.com/gorilla/mux</code></p> <p>it works!</p> <p>Is there a problem with mongo driver repo?</p> </div>

如何通过Elastica使用ES插件MongoDB河将MongoDB与Elastic Search连接起来

<div class="post-text" itemprop="text"> <p>i'm new to programming, so i apologize, if my question is very simple.</p> <p>First of all, I have installed and configured MongoDB and ES with MongoDB river, but i can't find how to do it via Elastica. My example is</p> <pre><code>curl -XPUT 'http://localhost:9200/_river/mongodb/_meta' -d '{ "type": "mongodb", "mongodb": { "db": "testTweets", "collection": "msgs" }, "index": { "name": "mongoindex", "type": "my_type" } }' </code></pre> <p>and also a query is</p> <pre><code>curl -XGET 'http://localhost:9200/mongoindex/_search?q=something&amp;pretty=true' </code></pre> <p>How can i write them using PHP and Elastica?</p> <p>I took as example </p> <pre><code>$elasticaType = $elasticaIndex-&gt;getType('tweet'); </code></pre> <p>and i can't find how to match the curl command with the right php code.</p> <p>I hope to be crystal clear! If you need any other to detail to give my a help, i will be very happy to add it.</p> <p>Thank you in advance!</p> <p>EDIT***</p> <p>A nice way to compose ElasticSearch analysis or mapping is the following chrome extension <a href="https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo" rel="nofollow">https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo</a> . It's very helpful for me.</p> </div>

mongo-go-driver通过_id查找文档

<div class="post-text" itemprop="text"> <p>I'm trying to find a document by its auto generated _id field. Code below returns nothing:</p> <pre><code>var documentID bson.RawValue documentID.Type = 7 documentID.Value = []byte("5c7452c7aeb4c97e0cdb75bf") objID := documentID.ObjectID() value := collection.FindOne(ctx, bson.M{"_id": objID}) </code></pre> <p>The value I provided is a real document id I got from Mongo Express </p> <pre><code>"_id": ObjectID("5c7452c7aeb4c97e0cdb75bf") </code></pre> <p>In case you're wondering why I bother with RawValue, I found examples using bson.EC.ObjectID but bson package doesn't seem to have EC type, also I found some examples mentioning github.com/mongodb/mongo-go-driver/bson/objectid package, but I could not find that package either. I previously developed with mgo but I'm new to mongo-go-driver, so if you can point an easy way to declare an ObjectID. </p> </div>

如何使用struct使用mongo-go-driver的更新功能

<div class="post-text" itemprop="text"> <p>The update function of mongo-go-driver can be called like this.</p> <pre class="lang-golang prettyprint-override"><code>filter := bson.D{"username", username} update := bson.D{{"$set", bson.D{ {"name", person.Name}, }, }} result, err := collection.UpdateOne(ctx, filter, update) </code></pre> <pre class="lang-golang prettyprint-override"><code>type Person struct { ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"` Username string `json:"username,omitempty" bson:"username,omitempty"` Name string `json:"name,omitempty" bson:"name,omitempty"` } </code></pre> <p>But, I need to call the update function using the <code>person</code> struct, without mentioning every field of person struct like this.</p> <pre class="lang-golang prettyprint-override"><code>filter := bson.D{"username", username} update := bson.D{{"$set", &lt;&lt;how to convert person struct to bson document?&gt;&gt;}} result, err := collection.UpdateOne(ctx, filter, update) </code></pre> <p>How can I convert the person struct to bson document?</p> </div>

官方mongo-go-driver使用会话

<div class="post-text" itemprop="text"> <p>Is there any example of using sessions with official mongodb driver for golang? I am trying to use sessions to take advantage from transactions and it seems that just reading tests on github I can’t find the way to do it.</p> <p>To be more specific I am struggling now with this:</p> <pre><code>session, err := pool.StartSession() if err != nil { log.Println("Could not create db session", err) return events.APIGatewayProxyResponse{ Body: err.Error(), StatusCode: http.StatusInternalServerError, }, err } ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() defer session.EndSession(ctx) var db *mongo.Database </code></pre> <p>Everything fine with code above but when I do:</p> <blockquote> <p><code>db = session.Database("testrest")</code></p> </blockquote> <p>It gives the error: </p> <blockquote> <p>session.Database undefined (type mongo.Session has no field or method Database)</p> </blockquote> <p>Which seems to work with mgo package… How do I select the database and run queries with session?</p> </div>

mongo-go-driver聚集调用始终返回错误

<div class="post-text" itemprop="text"> <p>I'm trying to do an aggregation with mongo-go-driver (MongoDB team driver for Golang) and I can't see what I'm doing wrong here: </p> <pre><code>// group group, e := bson.ParseExtJSONObject(` { "$group": { "_id":{ "ProductCode":"$ProductCode", "Dir":"$Dir", "WharehouseID":"$WharehouseID" } } } `) cursor, e := myCollection.Aggregate( context.Background(), group, ) // e output: "(Location40324) Unrecognized pipeline stage name: '_id'" </code></pre> <p>This is a mongodb error but if I execute this query in a mongodb native client I get the results and no error occurs. </p> </div>

mongo-go-driver投影阵列长度

<div class="post-text" itemprop="text"> <p>I'm trying to get a projection for the number of elements in a documents array.</p> <pre><code>options.SetProjection(bson.M{ "foo": true, "nrOfBars": bson.M{ "$size": "$bars" }, }) </code></pre> <p><code>bars</code> is the fieldname of the array.<br> This query though always returns 0 instead of the arrays length.</p> <p>How do I correctly query for the length of the array with the new mongo-go-driver?</p> </div>

在Mongo-go-driver中创建一个唯一字段

<div class="post-text" itemprop="text"> <p>I am very new to both Go and Mongodb and was writing my first rest-api with Go and Mongo. I am using <code>mongo-go-driver</code> and have the following <code>Modal</code> struct in Go </p> <pre><code>type Modal struct { Group []string `bson:"group" json:"group"` Hostname string `bson:"hostname" json:"hostname"` Overrides map[string]string `bson:"overrides" json:"overrides"` Excludes []string `bson:"excludes" json:"excludes"` } </code></pre> <p>I do not want to use the default <code>ObjectId</code> field provided by mongo-db as my primary key and instead would like to make the <code>Hostname</code> field as the primary key.</p> <p>If I make the type of <code>Hostname</code> field as <code>primitive.ObjectID</code>, then the <code>hostname</code> would be unique but its value will be randomly generated string by mongodb and not the actual hostname string value.</p> <p>So is there a way I can do this.</p> </div>

Golang MongoDB导入问题

<div class="post-text" itemprop="text"> <p>Facing issue importing golang mongodb driver. </p> <pre><code> go get -u go.mongodb.org/mongo-driver/mongo go get -u go.mongodb.org/mongo-driver/mongo@~1.0.0 </code></pre> <p><strong>package go.mongodb.org/mongo-driver/mongo: unrecognized import path "go.mongodb.org/mongo-driver/mongo" (https fetch: Get <a href="https://go.mongodb.org/mongo-driver/mongo?go-get=1" rel="nofollow noreferrer">https://go.mongodb.org/mongo-driver/mongo?go-get=1</a>: dial tcp: lookup go.mongodb.org: no such host)</strong></p> </div>

如何导入官方的mongodb驱动程序包

<div class="post-text" itemprop="text"> <p>How to import official mongoDB driver package in Go?</p> <p>I am following the official Go-mongoDB-driver package instruction (<a href="https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial" rel="nofollow noreferrer">https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial</a>). I have installed the mongoDB package using this:</p> <pre><code>go get github.com/mongodb/mongo-go-driver </code></pre> <p>but I just can't import the package</p> <p>I am doing a very simple snippet in my <code>main.go</code></p> <pre><code>package main import "github.com/mongodb/mongo-go-driver/mongo func main() { } </code></pre> <p>This gives me:</p> <pre><code>main.go:8:8: code in directory $GOPATH/src/github.com/mongodb/mongo-go-driver/bson expects import "go.mongodb.org/mongo-driver/bson" </code></pre> <p>When I tried to import <code>go.mongodb.org/mongo-driver/bson</code>, It gives me this:</p> <pre><code>main.go:10:8: cannot find package "go.mongodb.org/mongo-driver/bson" in any of: /usr/local/go/src/go.mongodb.org/mongo-driver/bson (from $GOROOT) $GOPATH/src/go.mongodb.org/mongo-driver/bson (from $GOPATH) </code></pre> <p>Kindly help, quite new in Go and not sure where to look since I don't find people having this issue a lot.</p> </div>

使用mongo-go-driver在mon中无法正常运行mongo.Connect()

<div class="post-text" itemprop="text"> <p>I am using the package: <code>"github.com/mongodb/mongo-go-driver/mongo"</code></p> <p>I am trying to use the following as specified in the <a href="https://godoc.org/github.com/mongodb/mongo-go-driver/mongo" rel="nofollow noreferrer">documentation</a>:</p> <pre><code>mongoContext, _ := context.WithTimeout(context.Background(), 10*time.Second) mongoClient, _ := mongo.Connect(mongoContext, "mongodb://localhost:27017") </code></pre> <p>However on the second line I get the error:</p> <pre><code>cannot use "mongodb://localhost:27017" (type string) as type *options.ClientOptions in argument to mongo.Connect </code></pre> <p>It seems the documentation doesn't match the implementation. Has anyone been successful?</p> <p><strong>The documentation states:</strong></p> <pre><code>//To do this in a single step, you can use the Connect function: ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) client, err := mongo.Connect(ctx, "mongodb://localhost:27017") </code></pre> </div>

如何使用Go的mongo驱动程序在Mongodb查询上创建视图?

<div class="post-text" itemprop="text"> <p>I am working with Golang and Mongodb. I am using <a href="https://godoc.org/gopkg.in/mgo.v2" rel="nofollow noreferrer">https://godoc.org/gopkg.in/mgo.v2</a> mongo driver for Go. I want to write views on my queries but I found that there is no function defined for that. Mongo Views is a recent feature provided in version 3.4. I have checked it in other driver also:</p> <p><a href="https://godoc.org/github.com/mongodb/mongo-go-driver/mongo" rel="nofollow noreferrer">https://godoc.org/github.com/mongodb/mongo-go-driver/mongo</a></p> <p>Its not even there. How can I get this feature in my driver ?</p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

Linux命令学习神器!命令看不懂直接给你解释!

大家都知道,Linux 系统有非常多的命令,而且每个命令又有非常多的用法,想要全部记住所有命令的所有用法,恐怕是一件不可能完成的任务。 一般情况下,我们学习一个命令时,要么直接百度去搜索它的用法,要么就直接用 man 命令去查看守冗长的帮助手册。这两个都可以实现我们的目标,但有没有更简便的方式呢? 答案是必须有的!今天给大家推荐一款有趣而实用学习神器 — kmdr,让你解锁 Linux 学习新姿势...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

史上最全的 python 基础知识汇总篇,没有比这再全面的了,建议收藏

网友们有福了,小编终于把基础篇的内容全部涉略了一遍,这是一篇关于基础知识的汇总的文章,请朋友们收下,不用客气,不过文章篇幅肯能会有点长,耐心阅读吧爬虫(七十)多进程multiproces...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

大学一路走来,学习互联网全靠这几个网站,最终拿下了一把offer

大佬原来都是这样炼成的

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

立即提问
相关内容推荐