Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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
      helpers: {
            children() {
                // Lấy danh sách tất cả users theo referrerId
                const children = User.find({ referrerId: this._id }).fetch()
                return children
            },
            childrenCount() {
                return this.children().count()
            }
        },
        behaviors: {
            timestamp: {
                hasCreatedField: true,
                createdFieldName: 'createdAt',
                hasUpdatedField: true,
                updatedFieldName: 'updatedAt'
            }
        }
    user .children() is children is not function
    someone please help, i really confuse with this
    Ly Nam
    @lyquocnam
    Can i create static method with astronomy ?
    Lukas Van Orshoven
    @Lukasvo
    @lyquocnam that should work. What does the rest of the code look like? Do you have a field also named children? Also, terminate your statements with semicolons, please
    On another topic: @jagi says here (jagi/meteor-astronomy#547) that an option like { modified: true } is implemented in the validate() function, but I can't find anything in the docs or the code. Is it not implemented? How could I use such a feature? It would greatly benefit the performance of my app
    Lukas Van Orshoven
    @Lukasvo
    Thank you, @andreyunugro! Too bad this isn't documented.
    Andreas West
    @a4xrbj1
    Hi guys, how do I remove a field from a collection in Astronomy? I'm currently using $unset: { temp: '' } but it seems that Astronomy is not allowing this operation to happen. I'm wondering what the equivalent is. Please that I don't want to set it to false or null, I want the field being deleted from my collection. Thanks in advance for your help!
    Andreas West
    @a4xrbj1
    Found this old thread: https://www.bountysource.com/issues/27982620-undefined-value-should-not-be-set-as-null-into-db where Lukas writes "And you can't unset a field for a single document because you want all data to be consistent" and further down he says " In Astronomy 2.0 it will be possible to unset a field but you will be doing it on your own risk :P"
    Luca Di Gaspero
    @liuq
    Hi all, I am trying to use class level validation, however the example in the documentation is not so helpful (being incorrect)
    validators: [
    firsName: [{
    type: 'minLength',
    param: 3
    }]
    ]
    I tried fixing it as
    validators: [{ type: "myCustomClassValidator" }] but i still get TypeError: ["Problem" class]["validators" property] Validators definition has to be an array of objects
    Andreas
    @andreyunugro
    @liuq You need to state your field key, for example:
    validators: [
      xxxField: [{ type: 'yourCustomClassValidator'}],
    ],
    Luca Di Gaspero
    @liuq
    Right, so it's not possible to define a real class-level validator (i.e., looking at all fields), this is just a place where to put field-level validation.
    Emad Radwan
    @EmadRadwan
    Hi There,
    Sorry for a pure beginner question. Does Astronomy provide alternative for Mongoose?
    Andrew Ckor
    @andrewckor
    No astronomy is only for meteor
    Alex Price
    @remotealex
    Is there a way to set e.trusted to false for testing purposes?
    Alex Price
    @remotealex
    Looking through the lib code it doesn't look like it... I'll override with NODE_ENV for now
    tanase-sebastian
    @tanase-sebastian
    Hello, does astronomy support the definition of relations between tables ? I see some github comments from 2015 but nothing more