micktaiwan/meteor-vermongo

Conflict between Vermongo and Collection2

Closed this issue · 13 comments

I have a collection that has autoFields using Collection2. These autofields are 'updated' (a date), and 'lastEditor' (a userId). When creating or editing records in the collection these are filled in automatically by collection2.

I am using vermongo for the collection, but not using your timestamp or userId options, as they would obviously be redundant.

Everything works fine, except in the case of delete, where updated and lastEditor are not set by collection2 to the time of the delete and user that performed the delete, nor are they set by vermongo since I have those options off (and they use different fieldnames).

What would you suggest is my best way of handling this scenario?

Should I fork a copy of vermongo to handle the delete case, or are there hooks you would recommend I could use to set the 'lastEditor' and 'updated' at the time of delete?

Is the redundancy not an option ?

I'd prefer not to have the data twice per record, of course, but it is an option - just not a preferable option.

From reading your code, options.userId seems to be used as the userId field name. If so, that is a help, I can specify options.userId = 'lastEditor' so as not to have that field duplicated. Its unfortunate that options.timestamp is a boolean and not a fieldname as well.

If options.timestamp were a fieldname, as well, I believe I could enable these options for vermongo and remove their definition as autofields from my collection2 definition.

I've published a version that will let you do that. Just set options.modifiedAt = 'updated'. But be careful options.createdAt will be set also. Tell me if it suits your project.

I think this can work! I can set the fieldnames of my createdAt, updatedAt and modifiedBy(userId) fields in vermongo and remove them from my autofield code in collection2.
I'll give it a try in the next few days and report back.
Thanks

Great !

Its better, but not quite there yet. When doing an update or delete the current userId is not being stored in the new version. I believe it is this test
!doc[options.userId]
The old version already has a doc[options.userId] so the test fails, and the current editors id is not being stored.

Could you give the part of your code where you are setting the collection with vermongo ? It should be something like this:

Requirements = new Meteor.Collection('requirements').vermongo({
  timestamps: true,
  userId: 'modifierId'
});

timestamps: true,
createdAt: 'submitted',
modifiedAt: 'updated',
userId: 'lastEditor',
ignoredFields: [],

The problem is that it should overwrite the userId (my lastEditor field) with the current userId, but your code doesn't do that because that field already has a value in the doc.

Actually, you probably need two options
option.createdBy (a fieldname)
option.updatedBy (a fieldname)
since these can be different, and not necessarily equal to userId
I manually set createdBy to an owner of the record which is not necessarily the current userId.

your code doesn't do that because that field already has a value in the doc

Vermongo will not set the field if you want to set it yourself.
If you want that vermongo take care of that for you, then do not set the lastEditor value in your form before updating your doc.

I manually set createdBy to an owner of the record which is not necessarily the current userId.

Good

I cant set the lastEditor during delete, since the record is written by vermongo, not me. It is this field that should have the current userId.

I'm thinking that my requirements may be too specific, so I have cloned your repository for my own specific need. But thank you for your help on this.