Example #1
0
 transactions() {
   if (!this._transactions) {
     const namespace = this.options().mongoNamespace;
     if (namespace) {
       this._transactions = new Mongo.Collection(`${namespace}/commandLog`);
       if (Meteor.isServer) {
         this._transactions._ensureIndex({ _eventIds: 1 }, {unique: true});
       }
     } else {
       this._transactions = new Mongo.Collection(null);
     }
   }
   return this._transactions;
 }
Example #2
0
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { serverFn } from '../lib';
import _ from 'lodash';

export const Posts = new Mongo.Collection('posts');

if (Meteor.isServer) {
    Posts._ensureIndex({
      'postName': 'text'
    });

    Meteor.publish('posts', function() {
        this.autorun(function() {
            return Posts.find();
        });
    });
}

// export const pagination = serverFn('pagination', true, function (type, limit, data) {
//   console.log("ServerSide", type, limit, data);
//     Posts.find({type: type}, {limit: limit, skip: data.selected * limit}).fetch();
// });
Example #3
0
    // https://www.meteor.com/tutorials/react/collections
    // https://www.meteor.com/tutorials/react/security-with-methods
    // https://www.meteor.com/tutorials/react/publish-and-subscribe

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import { getEmail, isAdmin, getAllStudentGrades } from '../api/authorizations';
import { Choices } from '../api/choices';
import { Timeslots } from '../api/timeslots';
import { currentYear } from '../startup/config';

export const OrderedChoices = new Mongo.Collection('orderedChoices');

if (Meteor.isServer) {
    OrderedChoices._ensureIndex({email: 1}, {unique: 1});
    Meteor.publish('orderedChoices', function orderedChoicesPublication() {
        var yearFilter = {}
        yearFilter["choices." + currentYear] = 1;
        return OrderedChoices.find({email : getEmail(this.userId)}, yearFilter);
    });
}

Meteor.methods({
    'orderedChoices.initialize'() {
        if (!isAdmin(this.userId)) {
            if (Meteor.isServer) {
                console.error('Initialize ordered choices: User is not admin.');
            }
            throw new Meteor.Error('not-authorized');
        }
Example #4
0
	ensureIndex(...args) {
		return this.model._ensureIndex(...args);
	}
Example #5
0
import { Match } from 'meteor/check';
import { Mongo, MongoInternals } from 'meteor/mongo';
import _ from 'underscore';
import { EventEmitter } from 'events';

const baseName = 'rocketchat_';

const trash = new Mongo.Collection(`${ baseName }_trash`);
try {
	trash._ensureIndex({ collection: 1 });
	trash._ensureIndex({ _deletedAt: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 30 });
} catch (e) {
	console.log(e);
}

const isOplogEnabled = MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle && !!MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle.onOplogEntry;

export class BaseDb extends EventEmitter {
	constructor(model, baseModel) {
		super();

		if (Match.test(model, String)) {
			this.name = model;
			this.collectionName = this.baseName + this.name;
			this.model = new Mongo.Collection(this.collectionName);
		} else {
			this.name = model._name;
			this.collectionName = this.name;
			this.model = model;
		}
Example #6
0
import { Mongo } from 'meteor/mongo'
import { GroupSchema } from './schema'
import { Meteor } from 'meteor/meteor'

export const Groups = new Mongo.Collection('Groups')
if (Meteor.isServer) {
  Groups._ensureIndex({ 'members.userId': 1 })
}
Groups.attachSchema(GroupSchema)
Example #7
0
import { Mongo } from 'meteor/mongo'
import { Meteor } from 'meteor/meteor'
import { GroupChatTopicSchema, GroupChatMessageSchema } from './schema'

export const GroupChatTopics = new Mongo.Collection('GroupChatTopics')
if (Meteor.isServer) {
  GroupChatTopics._ensureIndex({_id: 1, groupId: 1, 'wantToBeNotified.userId': 1})
  GroupChatTopics._ensureIndex({'wantToBeNotified.userId': 1})
}
GroupChatTopics.attachSchema(GroupChatTopicSchema)

export const GroupChatMessages = new Mongo.Collection('GroupChatMessages')
if (Meteor.isServer) {
  GroupChatMessages._ensureIndex({channelId: 1, createdAt: 1})
}
GroupChatMessages.attachSchema(GroupChatMessageSchema)
/* eslint-disable import/no-unresolved */
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
/* eslint-enable import/no-unresolved */

const Servers = new Mongo.Collection('presence:servers');

Servers._ensureIndex({ lastPing: 1 }, { expireAfterSeconds: 10 });
Servers._ensureIndex({ createdAt: -1 });

let serverId = null;
let isWatcher = false;
let observeHandle = null;
let exitGracefully = true;

const exitFunctions = [];

/* eslint-disable import/prefer-default-export */
export const ServerPresence = {};

const insert = () => {
    const date = new Date();
    serverId = Servers.insert({ lastPing: date, createdAt: date });
};

const runCleanupFunctions = (removedServerId) => {
    exitFunctions.forEach((exitFunc) => {
        exitFunc(removedServerId);
    });
};
Example #9
0
  */
Venue.prototype.editableBy = function(user) {
	if (!user) return false;
	var isNew = !this._id;
	return isNew // Anybody may create a new location
		|| user._id === this.editor
		|| UserPrivilegeUtils.privileged(user, 'admin'); // Admins can edit all venues
};

export default Venues = new Mongo.Collection("Venues", {
	transform: function(venue) {
		return _.extend(new Venue(), venue);
	}
});

if (Meteor.isServer) Venues._ensureIndex({loc : "2dsphere"});

Venues.Filtering = () => Filtering(
	{ region: Predicates.id
	}
);


Venues.facilityOptions =
	[ 'projector', 'screen', 'audio', 'blackboard', 'whiteboard'
	, 'flipchart', 'wifi', 'kitchen', 'wheelchairs'
	];

/* Find venues for given filters
 *
 * filter: dictionary with filter options
Example #10
0
File: log.js Project: schuel/hmmm
  *
  *  body (Object)
  *       Contents of the log entry. These are not indexed and depend on the
  *       track.
  */
export default Log = new Mongo.Collection('Log');

Log.Filtering = () => Filtering(
	{ start: Predicates.date
	, rel:   Predicates.ids
	, tr:    Predicates.ids
	}
);

if (Meteor.isServer) {
	Log._ensureIndex({ tr: 1});
	Log._ensureIndex({ ts: 1});
	Log._ensureIndex({ rel: 1});
}

/** Record a new entry to the log
  *
  * @param  {String} track   - type of log entry
  * @param  {String} rel     - related ID
  * @param  {Object} body    - log body depending on track
  */
Log.record = function(track, rel, body) {
	check(track, String);
	check(rel, [String]);
	check(body, Object);
	var entry =
Example #11
0
      }
    },
    uniforms: {
      label: null
    }
  },
  'createdAt': {
    type: Date,
    autoValue: () => new Date()
  }
}, {
  clean: {
    filter: true,
    autoConvert: true,
    removeEmptyStrings: true,
    trimStrings: true,
    getAutoValues: true
  }
})

Events.attachSchema(EventsSchema)

if (Meteor.isServer) {
  Events._ensureIndex({ 'address.location': '2dsphere' })
}

export {
  Events as default,
  EventsSchema
}
Example #12
0
// based on code from
    // https://www.meteor.com/tutorials/react/collections
    // https://www.meteor.com/tutorials/react/publish-and-subscribe

import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

const Authorizations = new Mongo.Collection('authorizations');

if (Meteor.isServer) {
    // make sure users don't have multiple authorization documents
    Authorizations._ensureIndex({email: 1}, {unique: 1});
    Meteor.publish('myEmail', function () {
        if (this.userId) {
            return Meteor.users.find({_id: this.userId}, {'services.google.email' : 1});
        }
        else {
            return [];
        }
    });
}

export function getEmail(userId) {
    var email = '';

    if (userId) {
        var user = Meteor.users.findOne({"_id": userId})
        // Since all users should be logged in with Google and we request email these fields should all exist,
        // once all data have become available
        if (user && user.services && user.services.google && user.services.google.email) {
Example #13
0
'use strict';

import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';

export const Places = new Mongo.Collection('places');

if (Meteor.isServer) {
  Places._ensureIndex({ 'location': '2dsphere' });
}
Example #14
0
/**
 * Created by danielsilva on 15/06/16.
 */
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';


export const Apartment = new Mongo.Collection('apartment');


if ( Meteor.isServer ) {
    Apartment._ensureIndex( { _id: 1, title: 1, owner: 1, price: 1, date: 1,description: 1, city:1} );

   /* Apartment.insert({
        title: "T5 APARTMENT MODERN RENEW ",
        owner: "Daniel Silva",
        price: "450€",
        date: new Date(),
        description: "Apartment for rent, One year min",
        city: "Faro"
    });*/
}

Apartment.allow({
    insert: () => false,
    update: () => false,
    remove: () => false
});

Apartment.deny({
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import 'meteor/aldeed:collection2';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import { check } from 'meteor/check';

export const NetworkMembers = new Mongo.Collection('networkMembers');

if (Meteor.isServer) {
	// This code only runs on the server

	NetworkMembers._ensureIndex( { "accountType" : 1 } );
	console.log('created networkMembers index')

	Meteor.publish('networkMembers', function networkMemberPublication() {
		return NetworkMembers.find();
  });

  Meteor.publish( 'memberSearch', function( search ) {
    check( search, Match.OneOf( String, null, undefined ) );

    let query      = {},
        projection = { limit: 10, sort: { name: 1 } };

    if ( search ) {
      let regex = new RegExp( search, 'i' );

      query = {
        $or: [
          { accountType: regex },
        ]