Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

c# - Manually supplying arguments to a MongoDB query to support collation feature (for case insensitive index)

I have installed the current development version 3.3.11 in order to test the case insensitive index that is apparently supported according to https://jira.mongodb.org/browse/SERVER-90. I have tried this from a mongo shell and a simple test database and it does seem to work.

Unfortunately, even though one specifies collation (and strength) during index creation, one must also specify the same collation params with .find in order to get case insensitive matches. If collation is omitted from the query, index behaves in a case sensitive fashion.

Even the newest C# MongoDB driver (2.3.0-beta1) does not seem to support supplying collation params to a query. So even though I have upgraded the engine and database, C# driver, created the index with required collation, I cannot seem to get the results using the current driver.

Is there a "manual" way of supplying extra arguments to a query?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is now possible in the newer version of the C# mongo driver (since 2.4.0).

For example, to query against a case-insensitive index:

IMongoCollection<SomeObject> someCollection;
var results = someCollection.Find<SomeObject>(x => x.name == someName,
  new FindOptions() {  Collation = new Collation("en", strength: CollationStrength.Secondary) } )

Notice that to enjoy the power of the index, you need to specify in the query the exact same collation parameter as specified when creating the index.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...