petersirka/nosql

database.nosql ??

dimitrilahaye opened this issue · 9 comments

Hi !
What do you mean for the database's path when you write :

var nosql = require('nosql').load('/users/petersirka/desktop/database.nosql');

What is the extension .nosql ?

Hello. In this case i used it only for test, but it was used to refer the
table document.

Hope it may help you.

Em Seg, 2 de mar de 2015 12:55, dimitrilahaye notifications@github.com
escreveu:

Hi !
What do you mean for the database's path when you write :

var nosql = require('nosql').load('/users/petersirka/desktop/database.nosql');

What is the extension .nosql ?


Reply to this email directly or view it on GitHub
#14.

Thanks for the speed answer ;)
But... excuse me, I am new in the noSQL world. How can I create this table document and what it looks like ?

No answer for a newbie ? ;)

Hi @dimitrilahaye,
you can create DB file like this:

var nosql = require('nosql').load('/users/petersirka/desktop/database.nosql');

nosql.insert({ table: 'A', name: 'New document in A' });
nosql.insert({ table: 'B', name: 'New document in B' });
nosql.insert({ table: 'A', name: 'New document in A' });

// Read all documents by table===A
nosql.all(function(doc) {
    return doc.table === 'A';
}, function(docs) {
    console.log(docs);
});

Do you understand? NoSQL DB doesn't support tables, you can store only documents.

So, when you indicate :

var nosql = require('nosql').load('/users/petersirka/desktop/database.nosql');

the document database.nosql is created ?

Yes :-), try it.

I will, promise ;)

Hey Peter - So each file is treated as one collection, right? Which is why there is no collection specified here:

nosql.insert({...})

Whereas mongo would be like:

db.MyCollection.insert({...})

So a more explanatory example would be:

var nosql = require('nosql');
var Users = nosql.load('/users/petersirka/desktop/users.nosql');
var Posts = nosql.load('/users/petersirka/desktop/posts.nosql');
Users.insert({id:1, name:'Peter'});

Posts.insert({id:1, user_id:1, title:"Peter's post", body: "Great post"});

Also, there is no automatic ID (aka _id) like mongo, right?

Hi @unformatt,

Each file is treated as one collection, right?

theoretically yes, but better name is "database"

Which is why there is no collection specified here:

nosql creates multiple readers and one writers and this is the problem in nosql.insert() and for it is need an instance. It's too complicated for its implementation.

Also, there is no automatic ID (aka _id) like mongo, right?
No, documents don't know about their identity. You must create your own, e.g. { id: new Date().getTime() }.

Thanks 👍