Giter Site home page Giter Site logo

Comments (4)

mitar avatar mitar commented on September 4, 2024

So it's recommended to setup a separate meteor instance running PeerDB to handle relations?

Yes, just so that your user facing instances and not slowed down because of the PeerDB work.

What happens if you try to do an insert from the server of a public facing meteor project connected to the Mongo database that fails on the separate PeerDB server due to validation? Does it fail on the public facing meteor instance without PeerDB?

PeerDB does not handle validation. It will warn you if it detects something strange, but is not preventing any writes or anything. If you want to do validation, do that before you write to the database.

Frankly, I never needed validation at the database level. Just make your queries correct and test things before deployment. :-)

BTW, MongoDB 3.0 has native validation support. Maybe look into that.

I imagine the errors on the PeerDB server can't propagate down to the Meteor server through Mongo (so I must be thinking about something incorrectly).

They do not propagate even when you are running only one instance, web instance together with PeerDB. PeerDB is asynchronous, it processes changes independently from the changes themselves. The idea is that you have eventually consistency. So you want a fast write which quickly returns (you should make sure that write is correct). And then once you make this change PeerDB will in the background propagate changes to all related documents, if you have defined any relations. Eventually they will all be updated.

How does PeerDB manage the collection hooks? Will everything work correctly if the insert/update/deletes aren't done from the meteor server with PeerDB?

PeerDB does not use collection hooks but it observes collections. So yea, changes can come to the database from anywhere, Meteor or even outside. The beauty of oplog.

but they all need the same logic taken into account should they try to do an invalid insert/update

For that you should use SimpleSchema or something like that. Or just verify manually. PeerDB does not validate or reject invalid inserts/updates. Frankly, I believe I see such code as simply buggy. If you release a buggy code which made problematic changes then I think it is better than just to fail validation (which might even make things worse) is to look at what exactly is going wrong and then fix data using a migration.

also need the relations managed.

That part is what PeerDB takes care of. You define relations declaratively and then the rest is taken care for you.

from meteor-peerdb.

jordangarside avatar jordangarside commented on September 4, 2024

Thanks a lot @mitar!

I have just one more question please:

The idea is that you have eventually consistency. So you want a fast write which quickly returns (you should make sure that write is correct).

So I need to insert the document with the referenced document if I want to do an immediate insert then read?

I can't do something like:

postId = Posts.insert
  text: "blah"
  author:
    _id: "ABC123"

post = Posts.findOne(postId)
authorName = post.author.name #This won't be available correct?

?

from meteor-peerdb.

mitar avatar mitar commented on September 4, 2024

It will not be available immediately, but if you do your query in a reactive context it will be available eventually. So all depends on your use case and how your particular code expects existence of values or can it handle lack of values in sub-documents.

The pattern which I currently use the most is that I do things like:

postId = Posts.insert
  text: "blah"
  author: _.pick(author, '_id', 'name')

So it turns out that often you anyway already have at least some version of the reference object around (you need _id anyway). So you can populate it yourself initially, and then you can make sure that PeerDB will assure data is recent.

Sometimes I even make a method on the Author class:

postId = Posts.insert
  text: "blah"
  author: author.getReference()

You are right that probably some of this could be automatized. For example, that you could just do:

postId = Posts.insert
  text: "blah"
  author: author

And it would automatically take only the fields you defined in the ReferenceField. But do not do it now. Currently the whole object would be stored and nobody would clear out the extra fields.

from meteor-peerdb.

jordangarside avatar jordangarside commented on September 4, 2024

Gotcha, thanks a ton @mitar !

from meteor-peerdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.