how to list all doc in a mongodb collection with sharedb-cli

88 views Asked by At

it is my client-demo. I want to get all doc in the "file" collection. but i get null

enter image description here

I use the mongo shell to test it. I find the doc data exists enter image description here

I'm sure the client connects to server successfully. cause when i invoke connection.get('file','test'), console log is the same as mongo shell. log text (Delta { ops: [ { insert: 'Hi!12323232' } ] }) enter image description here

i expected that query.results is an array contains correct docs.

1

There are 1 answers

0
childking_kk On

I find the answer in the sharedb document I should add the ready event callback:

var query = connection.createFetchQuery('file', {}, null);

query.on('ready', () => {
    query.results.forEach((doc) => console.log(doc.data));
});