In Meteor, how do you Insert/Upsert to a Meteor Collection with Unacknowldeged Write Concern w=0?
Can the write concern be set during the insert/upsert, rather than as a environment variable?
Yes, you can pass writeConcern as of Mongo v2.6:
http://docs.mongodb.org/manual/reference/command/insert/#dbcmd.insert
No, you can't pass that option in Meteor. It's not documented here:
http://docs.meteor.com/#update
I did some digging to see what you'd have to do if you wanted to patch Meteor. Here is the link to their update/insert/upsert code:
https://github.com/meteor/meteor/blob/devel/packages/mongo/collection.js
It looks like it delegates to DDP which is their Distributed Data Persistence framework. Hope that helps.
Related
Is there a way to create a proxy database for server(Node.js) tests (Mocha+ Chai). DB for development and production are created on MLab. But idea create one more DB especially for the tests seems to me not so good idea.
I agree with Thilo's answer that having a dedicated DB for tests is a good idea, but you can also use something like mongo-mock for this, which is an in-memory MongoDB instance you can use for tests.
I was wondering if there is something that I can use to mock my database. Say a function makeRelations makes relation from a certain node to another. I want to test this function but without actually making a relation in my database. Is there an easy way to do so ?
I am using expect and mocha for testing.
To access database (I don't have experience with arangodb), you typically use some driver library. You can fake that driver library calls with proxyquire.
You're testing what is likely already tested at some level.
There's some way to use more than one MongoDB database in meteor keeping reactivity/Oplog working? I've been reading about it (Post1), (Post2) and still I don't see a straighforward way to achieve this. It's possible? What's the right way? Thank you.
As you say; Default Connection isn't really an option as you can only have one DB and DDP is a bit superfluous when you only need a DB and none of the Meteor stuff. I'd think, therefore, your best approach would be to use the MongoInternals option.
The only thing missing from that option is reactivity; a method of enabling oplog tailing for these additional DB connections is mentioned in this answer. It essentially seems to be a case of passing the oplogUrl when creating the RemoteCollectionDriver, here's the example given in their answer:
var driver = new MongoInternals.RemoteCollectionDriver(
"mongodb://localhost:27017/db",
{
oplogUrl: "mongodb://localhost:27017/local"
});
var collection = new Mongo.Collection("Coll", {_driver: driver});
I'm going to write here what I've discovered until now, but I'm not going to mark the question as answered.
Concepts
What is reactivity?
Using reactivity, the data you show to your users will be updated in real time. You can enable or disable reactivity when you subscribe to a collection. Like this:
// enabled by default
Meteor.publish('top', function() {
return Top.find({},{reactive: false});
});
What is oplog?
Oplog is the MongoDB log. When you tell meteor to use oplog, reactivity performance is much better, unless you have a really high volumne of insert operations. In this cases may be wise to keep it disabled. Oplog can optimize your reactive DB calls by ~x5 ~x20.If you are going to use oplog you should optimize your db calls. You can read more about it here.
What methods exists to connect DBS to meteor?
Default connection:
Reactivity? yes. Oplog? yes. DB Limit? One. Description: Meteor creates a default MongoDB database when you run 'meteor'. You can set a different database using enviromental variables, or just MONGO_URL=mongodb://localhost:27017/db_name meteor.
DDP:
Reactivity? yes. Oplog? yes. DB Limit? no. Description: You need a meteor project for every DB. That's about 600MB in memory for every DB. You can read about it here and here.
MongoInternal (SOLUTION: Thanks to carlevans719):
Reactivity? yes. Oplog? yes. DB Limit? no. Description: You can specify a DB in your subscriptions file like:
ar database = new MongoInternals.RemoteCollectionDriver('mongodb://user:password#localhost:27017/meteor', {oplogUrl: "mongodb://localhost:27017/local"});
var numberOfDocs = database.open('boxes').find().count();
Last Words:
MongoInternal If you are not going to use the default db, you have to tell meteor to do not create it. To achieve this you must always run meteor as MONGO_URL=mongodb://localhost:27017 meteor
I search best way to sync my Backbone.Collection and Meteor MongoDB Collection.
What a best way for it? I want make POST/GET request thru the client.
Meteor already keeps your server collections and client-side cached collections in sync. If you wish to use backbone.js collections, you can do it in two ways.
First way: use an observe on MongoDB cursor, look for all 'added', 'changed' and 'removed' events and deal with them however you want. More in docs.
Second way: to keep memory consumption lower and not keep two copies of every object in both Minimongo and Backbone collections, you can go one level lower and use registerStore - client-side DDP API.
For API docs look at the source code. Also DDP specs can help, look at "Managing Data" section.
I want to create a node.js application using sails.js with the following DB design:
Products <----> ProductAttributes <----> Attributes
Please note that this is a given design and cannot be changed.
Althought sails.js does not support model associations yet, I want to know if it's possible for me to override the Model's CRUD methods or even create my own, in order to apply the above design to sails.js.
How can I do that?
If you want to get involved in the development of associations, send a note to the Google Group. In the mean time, what we do is, for SQL-based databases, use Model.query(), and for nosql databases, use two separate calls when you need to access the data.
Hope that helps, and look out for updates from us on this as the summer progresses.
You can use the associations in the Sails.js v0.10. npm install sails#git://github.com/balderdashy/sails.git#v0.10
and here is the documentation.. https://github.com/balderdashy/sails-docs/blob/master/reference/ModelAssociations.md