第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

MongoDB 不同的查詢和 $in 與 Go

MongoDB 不同的查詢和 $in 與 Go

Go
絕地?zé)o雙 2022-06-01 18:23:44
我在 MongoDB 中的不同查詢遇到問(wèn)題。我可以在 Mongo shell 中編寫(xiě)它,它可以工作,但我不知道如何在 Go 代碼中實(shí)現(xiàn)它。這是我的 Mongo shell 代碼db.getCollection('company_role_function').distinct("rolecode", {rolecode : {   $in: ['DHBK_ROLE_01','DHBK_ROLE_03' ] },productid:'IOT_Platform'})這是我的 Go 代碼1.profile.go    type CompanyRoleFunction struct {        Rolecode     string `json:"rolecode"`        Productid    string `json:"productid"`        Functioncode string `json:"functioncode"`        Comid        string `json:"comid"`     }存儲(chǔ)庫(kù).gopackage repositoryimport "bitbucket.org/cloud-platform/vnpt-sso-usermgnt/model"type IProfileRepository interface {   FindRoleByUserProduct(string) (*model.CompanyRoleFunction, error)}mongo_driver.gopackage repositoryimport (    "bitbucket.org/cloud-platform/vnpt-sso-usermgnt/model"    "go.mongodb.org/mongo-driver/bson"    "gopkg.in/mgo.v2")type ProfileRepositoryMongo struct {  db         *mgo.Database  collection string } func NewProfileRepositoryMongo(db *mgo.Database, collection string) *ProfileRepositoryMongo {    return &ProfileRepositoryMongo{    db:         db,    collection: collection,   }}//I HAVE TROUBLE HERE func (r *ProfileRepositoryMongo) FindRoleByUserProduct(rolecode arr[]string)  (*model.CompanyRoleFunction, error) {  var companyRoleFunction model.CompanyRoleFunction   //I HAVE TROUBLE HERE  err := r.db.C(r.collection).Find(bson.M{"username": username}).One(&companyRoleFunction)   //I HAVE TROUBLE HERE  if err != nil {      return nil, err   }  return &companyRoleFunction, nil }
查看完整描述

1 回答

?
料青山看我應(yīng)如是

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊

嘗試以下代碼在 mgo 中區(qū)分


package main


import (

"context"

"fmt"

"time"


"go.mongodb.org/mongo-driver/bson"

"go.mongodb.org/mongo-driver/mongo"

"go.mongodb.org/mongo-driver/mongo/options"

"gopkg.in/mgo.v2"

)


type Result struct {

Rolecode string `json:"rolecode"`

Productid string `json:"productid"`

Functioncode string `json:"functioncode"`

Comid string `json:"comid"`

}

type Results []Result


func main() {

//delete1("GV_BMVT")

//update("GV_BMVT")

check()

}


func check() {

session, err := mgo.Dial("mongodb://casuser:Mellon@222.255.102.145:27017/users")

if err != nil {

panic(err)

}

c := session.DB("users").C("company_role_function")

results := []string{}


roleArray := []string{"DHBK_ROLE_01,", "DHBK_ROLE_03"}

err = c.Find(bson.M{"rolecode": bson.M{"$in": roleArray}, "productid": "IOT_Platform"}).Distinct("rolecode", &results)

if err != nil {

panic(err)

}

fmt.Println(results)



}


查看完整回答
反對(duì) 回復(fù) 2022-06-01
  • 1 回答
  • 0 關(guān)注
  • 252 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)