Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

couchbase - Why querying a composite-key-view with multiple keys (surely existing) from .net SDK 3.1 returns zero results? What is the correct format for that?

I have index with the following Map function (and no reduce function):

  if (doc.someId && doc.anotherId)
  {
                emit([doc.someId, doc.anotherId], doc);
  }

SomeId is int, and anotherId is string.

I'm using dotnet SDK 3.1 (https://www.nuget.org/packages/CouchbaseNetClient/3.1.1) to query the view like so:

var options = new ViewOptions();

object id = new object[] { 123, "777" };
options.Key(ids);

IViewResult<object, T> result;
result = await bucket.ViewQueryAsync<object, T>(designDocument, viewName, options);
var rows = await result.Rows.Select(r => r.Value).ToListAsync();

(designDocument and viewName are correct, connection established)

And I get the correct document successfully.

But when I want to query with multiple keys using the 'options.Keys()' function I get zero results (again both key surly existing in couchbase):

object[,] ids = new object[,] { { 123, "777" }, { 456, "888" } };
options.Key(ids);
IViewResult<object, T> result;
result = await bucket.ViewQueryAsync<object, T>(designDocument, viewName, options);
var rows = await result.Rows.Select(r => r.Value).ToListAsync();

Even if I try to use only one of the composite keys, but with array of arrays to 'Keys()' function not single array to 'Key()' function.

object[,] ids = new object[,] { { 123, "777" } };
options.Keys(ids);

Zero.

object[,] ids = new object[,] { { 456, "888" } };
options.Keys(ids);

Zero.

object id = new object[] { 123, "777"  };
options.Key(id);

One result.

Why is this happening? Is this the correct format? It used to be the format on older version of dotnet SDK.

I also tried to use different Type at the ViewQueryAsync generic functin with no luck.

The documentation for this SDK is very poor and I couldn't find any example or explanation of the format needed.

question from:https://stackoverflow.com/questions/65907252/why-querying-a-composite-key-view-with-multiple-keys-surely-existing-from-net

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

1 Reply

0 votes
by (71.8m points)

After investigation with fiddler the old SDK version (1.0), and the new one - the format sent in the incorrect way (SDK 3.1) was

[[[123:"777"],[456:"888"]]]

and the correct one(SDK 1.0) was

[[123:"777"],[456:"888"]]

with postman i tried to use the first format and it worked.

so I tried passing to the Keys function array like so :

options.Keys(new object[]{123, "777"}, new object[]{456, "888"});

and it worked. the format was correct. and I got results.

the Keys function accepts

params object[]? keys

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...