qmgo icon indicating copy to clipboard operation
qmgo copied to clipboard

collation support ?

Open zzycn003 opened this issue 3 years ago • 7 comments

Hi

Looks like qmgo does not suport collation ? https://docs.mongodb.com/manual/reference/collation/

I have two usecases that depends on collation:

  1. when create index
  2. when find with case insensitve match ( search user by username which is case insensitive)

The original mongo driver does support collation. Looks like that qmgo not. Am I right ?

Thanks

zzycn003 avatar Jun 03 '21 09:06 zzycn003

Most operations of Qmgo have collation by parameter option, but sadly,Qmgo doesn't have collation when create Index in current version.

jiangz222 avatar Jun 05 '21 07:06 jiangz222

@jiangz222 thanks for your reply.

Then, in qmgo, is there any way or workaround that I can do a search with case insensitive, saying search user by username. I know regexp is an option, is there any other options ?

zzycn003 avatar Jun 07 '21 00:06 zzycn003

Most operations of Qmgo have collation by parameter option, but sadly,Qmgo doesn't have collation when create Index in current version.

You said most operations of qmgo support collation with an option, does Find()/One() support collation ? From below qmgo code, I didn't understand how. Is there an example ? thanks

func (q *Query) One(result interface{}) error { if len(q.opts) > 0 { if err := middleware.Do(q.opts[0].QueryHook, operator.BeforeQuery); err != nil { return err } } opt := options.FindOne()

if q.sort != nil {
	opt.SetSort(q.sort)
}
if q.project != nil {
	opt.SetProjection(q.project)
}
if q.skip != nil {
	opt.SetSkip(*q.skip)
}
if q.hint != nil {
	opt.SetHint(q.hint)
}

err := q.collection.FindOne(q.ctx, q.filter, opt).Decode(result)

if err != nil {
	return err
}
if len(q.opts) > 0 {
	if err := middleware.Do(q.opts[0].QueryHook, operator.AfterQuery); err != nil {
		return err
	}
}
return nil

}

zzycn003 avatar Jun 07 '21 00:06 zzycn003

Most operations of Qmgo have collation by parameter option, but sadly,Qmgo doesn't have collation when create Index in current version.

You said most operations of qmgo support collation with an option, does Find()/One() support collation ? From below qmgo code, I didn't understand how. Is there an example ? thanks

func (q *Query) One(result interface{}) error { if len(q.opts) > 0 { if err := middleware.Do(q.opts[0].QueryHook, operator.BeforeQuery); err != nil { return err } } opt := options.FindOne()

if q.sort != nil {
	opt.SetSort(q.sort)
}
if q.project != nil {
	opt.SetProjection(q.project)
}
if q.skip != nil {
	opt.SetSkip(*q.skip)
}
if q.hint != nil {
	opt.SetHint(q.hint)
}

err := q.collection.FindOne(q.ctx, q.filter, opt).Decode(result)

if err != nil {
	return err
}
if len(q.opts) > 0 {
	if err := middleware.Do(q.opts[0].QueryHook, operator.AfterQuery); err != nil {
		return err
	}
}
return nil

}

Not yet! 😢

jiangz222 avatar Jun 08 '21 05:06 jiangz222

@jiangz222 thanks for your reply.

Then, in qmgo, is there any way or workaround that I can do a search with case insensitive, saying search user by username. I know regexp is an option, is there any other options ?

About this, sadly, Qmgo can't do anything more than official driver.

jiangz222 avatar Jun 08 '21 11:06 jiangz222

请问这个问题解决了吗?我需要collation对中文字段按照拼音进行排序,有其它的解决方案吗? 谢谢!

brucezhao avatar Feb 09 '23 10:02 brucezhao

请问这个问题解决了吗?我需要collation对中文字段按照拼音进行排序,有其它的解决方案吗? 谢谢!

这个功能我记得有, 是在选项里面设置排序方式.

888go avatar Feb 23 '24 04:02 888go