Skip to content

Instantly share code, notes, and snippets.

View bhunjadi's full-sized avatar

Berislav Hunjadi bhunjadi

  • Zagreb, Croatia
View GitHub Profile
@bhunjadi
bhunjadi / mongo-count.ts
Created May 12, 2020 08:05
Patch mongodb cursor.count to be used with mongo transactions
import {MongoInternals} from 'meteor/mongo';
const RawCollection = MongoInternals.NpmModule.Collection;
const Cursor = MongoInternals.NpmModule.Cursor;
const CountDocumentsOperation = MongoInternals.NpmModule.Operations;
RawCollection.prototype.count = function (...args) {
return this.countDocuments(...args);
};
@bhunjadi
bhunjadi / aggregate.js
Created May 6, 2019 15:18
Meteor aggregate with support for Decimal fields, custom types...
// var MongoDB = NpmModuleMongodb;
var MongoDB = MongoInternals.NpmModules.mongodb.module;
// just beautiful copy paste from mongo_driver.js
// This is used to add or remove EJSON from the beginning of everything nested
// inside an EJSON custom type. It should only be called on pure JSON!
var replaceNames = function (filter, thing) {
if (typeof thing === "object" && thing !== null) {
if (_.isArray(thing)) {