petersirka / nosql

NoSQL embedded database for small node.js projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

database.counter.count throws error

biomade opened this issue · comments

I am trying to test the DatabaseCounter count method; per the documents both the parameters (id and callback) are optional. So when I run the following
var dbNewsletter = db.load('db/newsletter.nosql'); var mycounter = dbNewsletter.counter.count('id'); console.log(mycounter)

I get the following

Counter {
TIMEOUT: 30000,
db:
Database {
filename: 'db/newsletter.nosql',
filenameTemp: 'db/newsletter.nosql-tmp',
filenameMeta: 'db/newsletter.meta',
directory: 'db',
filenameBackup: 'db\newsletter_backup.nosql',
name: 'newsletter',
pending_update: [],
pending_append: [],
pending_reader: [],
pending_reader_view: [],
pending_remove: [],
views: {},
step: 0,
pending_drops: false,
pending_views: false,
binary:
Binary {
db: [Circular],
directory: 'db/newsletter-binary/',
exists: false },
counter: [Circular],
inmemory: {} },
key: 'nosql1102578873',
type: 2 }
C:\Users\laurie\Documents\GitHub\NoSQLTest\node_modules\nosql\index.js:1877
callback(null, single ? (type ? output : 0) : (all ? EMPTYARRAY : output));
^

TypeError: callback is not a function
at ReadStream. (C:\Users\laurie\Documents\GitHub\NoSQLTest\node_modules\nosql\index.js:1877:3)
at emitOne (events.js:96:13)
at ReadStream.emit (events.js:188:7)
at fs.js:1942:12
at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nosqltest@0.0.1 Counter: node counter.js

@biomade dbNewsletter.counter.count('id'); because it doesn't contain any callback ....

I tried that too
code:
var dbNewsletter = db.load('db/newsletter.nosql');
var mycounter = dbNewsletter.counter.count('id');
console.log(mycounter)

and this is the error I got
Counter {
TIMEOUT: 30000,
db:
Database {
filename: 'db/newsletter.nosql',
filenameTemp: 'db/newsletter.nosql-tmp',
filenameMeta: 'db/newsletter.meta',
directory: 'db',
filenameBackup: 'db\newsletter_backup.nosql',
name: 'newsletter',
pending_update: [],
pending_append: [],
pending_reader: [],
pending_reader_view: [],
pending_remove: [],
views: {},
step: 0,
pending_drops: false,
pending_views: false,
binary:
Binary {
db: [Circular],
directory: 'db/newsletter-binary/',
exists: false },
counter: [Circular],
inmemory: {} },
key: 'nosql1102578873',
type: 2 }

That's what I have been looking at... which really isn't helping.

dbNewsletter.counter.count('id', function(err, response) {
    console.log(response);
});

Yes, but why does the documentation say the parameters are optional, and when I do put in the parameters, I get a ZERO as a result and I have 4 records in my db
{"id":1,"name":"laurie","email":"laurie@gmail.com"}
{"id":2,"name":"erich","email":"erich@gmail.com"}
{"id":3,"name":"mary","email":"mary@gmail.com"}
{"id":12,"name":{"first":"jon","last":"doe"},"address":{"street":"123 main","city":"NYC","state":"NY","zip":"11760"}}

I have fixed documentation.

thanks.