ViewQuery with Node yields no results


#1

Hello,

I am trying to retrieve data from a predefined ViewQuery that should grab all the documents in the default bucket. The ViewQuery is as follows…

function (doc. meta)
{
emit(meta.id, null);
}

In the console tool, this does indeed grab everything from the bucket, however when accessed programmatically there seems to be a refresh problem. Basically, all in the same program, I do the following…

1, Clear (flush) the default bucket (after having set the flush flag on the bucket using the console)
2. Load 100 documents into it using Bucket::insert.
3. Execute a query against the above ViewQuery

The query returns nothing. However, when I run the program again (with the flush part disabled, i.e. the old data from the previous run is left intact), the query returns the data from the previous execution (i.e. the first 100 documents that were loaded as opposed to all 200 documents that are now in there).

I see someone has posted a similar issue where something like this is mentioned…

function (doc, meta) {
if (doc.CacheElementMap.objectType==“CacheElementMap”)
{
emit(doc.CacheElementMap.caseId,doc);
}
}

…but this does not work for me.

A ‘value’ JSON example is…

{
“type”: “balances”,
“balance”: 99.29215766023844
}

…an example key is…

306e9e3266812c853cc90225c7affbf35c8d7131

Any ideas?

Thanks,

Matthew


#2

Matthew,

What version of Cocuhbase are you using? Also, from the “insert” method you mention it appears you are using a version of the node client before 2.0? Also are using stale=false with your view query?

Thanks

Todd


#3

Hello Todd,

I’m on Version: 3.0.1 Community Edition (build-1444) of Couchbase. As for the Node driver, I installed it using npm within the last month (npm install couchbase). Running npm list gives…

├─┬ couchbase@2.0.4
│ ├── bindings@1.2.1
│ ├── jsonparse@0.0.6
│ ├── nan@1.3.0
│ └─┬ request@2.45.0
│ ├── aws-sign2@0.5.0
│ ├─┬ bl@0.9.3
│ │ └─┬ readable-stream@1.0.33
│ │ ├── core-util-is@1.0.1
│ │ ├── inherits@2.0.1
│ │ ├── isarray@0.0.1
│ │ └── string_decoder@0.10.31
│ ├── caseless@0.6.0
│ ├── forever-agent@0.5.2
│ ├─┬ form-data@0.1.4
│ │ ├── async@0.9.0
│ │ ├─┬ combined-stream@0.0.7
│ │ │ └── delayed-stream@0.0.5
│ │ └── mime@1.2.11
│ ├─┬ hawk@1.1.1
│ │ ├── boom@0.4.2
│ │ ├── cryptiles@0.2.2
│ │ ├── hoek@0.9.1
│ │ └── sntp@0.2.4
│ ├─┬ http-signature@0.10.1
│ │ ├── asn1@0.1.11
│ │ ├── assert-plus@0.1.5
│ │ └── ctype@0.5.3
│ ├── json-stringify-safe@5.0.0
│ ├── mime-types@1.0.2
│ ├── node-uuid@1.4.2
│ ├── oauth-sign@0.4.0
│ ├── qs@1.2.2
│ ├── stringstream@0.0.4
│ ├─┬ tough-cookie@0.12.1
│ │ └── punycode@1.3.2
│ └── tunnel-agent@0.4.0

…so I assume am on 2.0.4.

Thanks,

Matthew


#4

Hey Matthew,

Please ensure you are waiting until all of the documents you are inserting completely insert (you get the callback), and additionally are specifying stale(UPDATE_AFTER) for you’re query (to force the query to wait for the view index to get up to date with the data you’ve inserted).

Cheers, Brett