Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    pit999
    @pit999
    How can I use MongoObservable (import { MongoObservable } from 'meteor-rxjs';)
    Alex Price
    @remotealex
    Is there a nice way to prevent the updating of a field entirely? I'm extending the Meteor.users collection and want to safeguard against updating emails and passwords though the Astro class
    Alex Price
    @remotealex
    Ah! there is an immutable flag <3
    J3m5
    @J3m5
    Hi! I don't understand how to use Validators. I would like to use it to validate a method in the server side extended method, but I don't know where to put the validate method. In the class? Server-side? Client side?
    J3m5
    @J3m5
    And does the validate method replace the save method? I'm a bit confused, the doc doesn't seem clear to me.
    Andreas
    @andreyunugro
    Hi @J3m5, here the documentation link to create custom validators: https://jagi.github.io/meteor-astronomy/#creating-validators
    I recently defined it in the same file js as schema definition
    So it is server side, you can define it in the same file as schema definition, and after you defined it, you can use it in the fields definition
    AFAIK, Validate method add validation when you call .save();
    J3m5
    @J3m5
    Thank you for your answer. I have succeeded to use it. For now, I don't use custom validators. I use the validate method in the server side class and i do the save() in the else of the "if(ValidationError.is(err)) {}". It works pretty well like that. It gives me this:
     this.validate({
                    fields: ['name']
                }, (err) => {
    
                    if (ValidationError.is(err)) {
                        throw new Meteor.Error();
                    } else {
                        return this.save();
    }
    Andrew Ckor
    @andrewckor
    Hello guys!
    I'm using Astronomy for a long time, it used to work perfectly. But when I updated to meteor 1.6 I keep getting errors on save();
    Exception while invoking method '/Astronomy/execute' TypeError: Class is not a constructor
    I20171103-20:10:21.932(2)?     at DDPCommon.MethodInvocation.astronomyExecute (packages/jagi:astronomy/lib/modules/methods/meteor_methods/astronomyExecute.js:22:11)
    I20171103-20:10:21.933(2)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1768:12)
    I20171103-20:10:21.933(2)?     at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
    I20171103-20:10:21.933(2)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1134:15)
    I20171103-20:10:21.934(2)?     at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
    I20171103-20:10:21.934(2)?     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1134:15)
    I20171103-20:10:21.934(2)?     at Promise (packages/ddp-server/livedata_server.js:715:46)
    I20171103-20:10:21.934(2)?     at new Promise (<anonymous>)
    I20171103-20:10:21.934(2)?     at Session.method (packages/ddp-server/livedata_server.js:689:23)
    I20171103-20:10:21.934(2)?     at packages/ddp-server/livedata_server.js:559:43
    I see more people getting this in older issues, but not anymore, and I don't know if it's my problem or meteor.
    Andrew Ckor
    @andrewckor
    I fixed it guys!!
    Not sure though why all this time used to work :/
    I imported my classes into server and it worked.
    import '../imports/api/classes/Customer';
    import '../imports/api/classes/Brand';
    Alex Price
    @remotealex
    Is there a definitive way to do an auto-incrementing field in astronomy? I've read the main issue on it and noticed it was on the list for the 2.0 road map but never got checked off!
    I'm going to try and use this https://github.com/usefulio/meteor-mongo-counter/ :)
    Alex Price
    @remotealex
    That package seems well out of date. Going to roll with mongodb-counter
    Andreas
    @andreyunugro
    I think you can use and define event beforeInsert, increment the value in that event.
    // In your schema definition, add event beforeInsert:
    events: {
        beforeInsert(e) {
          const latest = XXX.findOne({}, {
            sort: { YYY: -1 },
          });
          e.currentTarget.YYY = (typeof latest === 'undefined') ? 1 : latest.YYY + 1;
        },
      },
    Just add to your alternative way to do it.. :)
    Andreas
    @andreyunugro
    Note: XXX is your class (not collection) name, YYY is your auto increment field.
    Alex Price
    @remotealex
    Thanks @andreyunugro, this is similar to what I wrote originially, but read somewhere it wasnt reliable with lots of writes
    the mongodb-counter solution i came up with works well
    Andreas
    @andreyunugro
    Awesome!! Can you share some snippet? :D Maybe usefull to others..
    Alex Price
    @remotealex
    yeah let me have a look, might be worth packaging up
    It's not worth it imo, its pretty simple though
    ...
    import MongoCounters from 'mongodb-counter';
    
    // Setup the counters object used for auto-incrementing
    const path = `${process.env.PWD}/pm2-meteor.json`;
    const json = fs.readFileSync(path, 'utf8');
    const config = JSON.parse(json);
    
    const counters = MongoCounters.createCounters({
      mongoUrl: config.env.MONGO_URL
    });
    
    const Invoice = Class.create({
      ...
    
      events: {
        beforeInsert(e) {
          const invoice = e.currentTarget;
    
          // Wrap the counters increment and get method so they're
          // synchronous. I tried to use the callback methods as
          // in the docs for mongo-counter, but it didnt work
          Meteor.wrapAsync(counters('invoiceId').increment)();
    
          const nextId = Meteor.wrapAsync(counters('invoiceId').get)();
    
          if (typeof nextId === 'number') {
            invoice.invoiceId = nextId;
          }
        }
      },
      ...
    Alex Price
    @remotealex
    Just a reflection on the above code, you cant use fs on the client, so I've now changed it to use ENV variables rather than reading the config file!
    Is there a way to create/call static methods in Astro?
    Alex Price
    @remotealex
    Currently my code looks like : new User().callMethod('findUserByEmail', ... and i find it anoying and hard to read. I'd much rather have User.callMethod('findUserByEmail', ... (I've tested that and it doesn't work)
    Andreas
    @andreyunugro
    Alex Price
    @remotealex
    yeah I guess that would work! Can you have server only helpers?
    shaliniloop
    @shaliniloop
    i have schema in meteor
    import { Enum } from 'meteor/jagi:astronomy';
    const Status = Enum.create({
    name: 'Status',
    identifiers: {
    New: 1,
    progress: 2,
    Complete :3
    }
    });
    status: {
    type: Status,
    defaultValue: 1,
    }
    i want to ruin update query
    run*
    var findVar = Orders.update({"_id": "w46xKnB3pFniNiwoJ"},{$set: { "status" : "3"} })
    console.log(findVar);
    }
    but it gives error
    update failed: Error: Status must be of type Enum
    can anyone help in this?
    Andreas
    @andreyunugro
    @alexpriceonline Actually, currently I use meteor as server only. So I can not sure whether helper can be used for server only. But you always able to use Meteor.isServer check. :smile:
    @shaliniloop Hi, do you still need help on this? What is your schema classname?
    Andreas
    @andreyunugro
    I usually use Enum with identifiers option using array, and this is example how I define default value:
    // Define FileStatus enum.
    const FileStatus = Enum.create({
      name: 'FileStatus',
      identifiers: ['TEMPORARY', 'PERMANENT'],
    });
    // Inside schema definition.
    status: {
        type: FileStatus,
        default: FileStatus.TEMPORARY,
    },
    Andreas
    @andreyunugro
    And this is example how to use it.
    // Import file schema and file status enum.
    import { File, FileStatus } from '/imports/classes/File.js';
    // Trying to create new file with permanent status.
    const file = new File();
    file.status = FileStatus.PERMANENT;
    file.save();
    Ly Nam
    @lyquocnam
    hello guys i try create helpers but it not show when call