Morning All,
New to the forum and looking fwd to sharing my cb experience and wonderment.
i’m working on a couchbase app here as a proof-of-concept for some projects i would like to do.
So far things have gone quite well but there was a bit of learning curve for me regarding memcache%.
i’ve populated a cache with about 3 mm objects and i’m trying to query the data by indexing one of the fields (not querying key). Objects were serialized from anonymous types (?could be my problem depending on how they deserialize from view when i only select certain fields?).
So i’ve read that views are the answer as you can predefine them, gen indexes and specify what is returned.
when i exec GetView and try to traverse the enumerable i get this error:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘Couchbase.IViewRow’ because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly
i’m hoping this has happened to someone else but, below are the details of my use case, with instrument as key for the view:
my json object
{
"_id": “USDJPY-JPFL-Curncy|2/14/2014 4:09:00 PM”,
“time_in_utc_date”: “2/14/2014 4:09:00 PM”,
“instrument”: “USDJPY JPFL Curncy”,
“time_in_utc”: “2/14/2014 4:09:00 PM”,
“time_in_est”: “2/14/2014 11:09:00 AM”,
“open”: “101.83”,
“high”: “101.83”,
“low”: “101.83”,
“close”: “101.83”,
“num_of_events”: “6”,
“volume”: “0”,
“load_date”: “3/3/2014 11:35:38 AM”
}
map code
function (doc, meta) {
if (doc.instrument)
emit(doc.instrument,[doc.time_in_utc, doc.open,doc.close,doc.high, doc.low] );
}
metadata
{
“id”: “USDJPY-JPFL-Curncy|2/14/2014 4:09:00 PM”,
“rev”: “1-0000625ddf0bc0e30000000000000112”,
“expiration”: 0,
“flags”: 274,
“type”: “json”
}
GetView output from couchbase admin(browser)
{“total_rows”:5274,“rows”:[
{“id”:“1802-JT-Equity|4/17/2014 3:29:00 AM”,“key”:“1802 JT Equity”,“value”:[“4/17/2014 3:29:00 AM”,“622”,“621”,“622”,“621”]},
{“id”:“1812-JT-Equity|4/17/2014 1:22:00 AM”,“key”:“1812 JT Equity”,“value”:[“4/17/2014 1:22:00 AM”,“384”,“386”,“386”,“384”]},
{“id”:“1824-JT-Equity|4/17/2014 12:56:00 AM”,“key”:“1824 JT Equity”,“value”:[“4/17/2014 12:56:00 AM”,“731”,“731”,“731”,“731”]},
{“id”:“1883-JT-Equity|4/17/2014 1:01:00 AM”,“key”:“1883 JT Equity”,“value”:[“4/17/2014 1:01:00 AM”,“1539”,“1539”,“1539”,“1539”]},
{“id”:“1885-JT-Equity|4/17/2014 12:48:00 AM”,“key”:“1885 JT Equity”,“value”:[“4/17/2014 12:48:00 AM”,“197”,“197”,“197”,“197”]},
{“id”:“1919-JT-Equity|4/17/2014 5:55:00 AM”,“key”:“1919 JT Equity”,“value”:[“4/17/2014 5:55:00 AM”,“118”,“118”,“118”,“118”]},
{“id”:“1954-JT-Equity|4/17/2014 1:29:00 AM”,“key”:“1954 JT Equity”,“value”:[“4/17/2014 1:29:00 AM”,“476”,“476”,“476”,“476”]},
{“id”:“1961-JT-Equity|4/17/2014 12:02:00 AM”,“key”:“1961 JT Equity”,“value”:[“4/17/2014 12:02:00 AM”,“615”,“615”,“615”,“615”]},
{“id”:“1969-JT-Equity|4/17/2014 12:16:00 AM”,“key”:“1969 JT Equity”,“value”:[“4/17/2014 12:16:00 AM”,“996”,“996”,“996”,“996”]},
{“id”:“2175-JT-Equity|4/17/2014 12:45:00 AM”,“key”:“2175 JT Equity”,“value”:[“4/17/2014 12:45:00 AM”,“1955”,“1955”,“1955”,“1953”]}
]
}
**this is my C# client code
var results = CouchbaseManager.Instance.GetView(“dev_test”, “ticker”);
foreach (var row in results)
{
Console.WriteLine("Row ID: " + row.ItemId);
Console.WriteLine("Row Key: " + row.ViewKey[0]);
Console.WriteLine("Row Value: " + row.Info[“value”]);
}
i greatly appreciate any help provided
Thanks
Allen