-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo-instances.js
35 lines (30 loc) · 884 Bytes
/
mongo-instances.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* global CollectionExtensions */
import { Mongo } from 'meteor/mongo'
import { Meteor } from 'meteor/meteor'
const instances = []
CollectionExtensions.addExtension(function (name, options) {
instances.push({
name: name,
instance: this,
options: options
})
})
Mongo.Collection.get = function (name, options) {
options = options || {}
const collection = instances.find(instance => {
if (options.connection) {
return (
instance.name === name &&
instance.options &&
instance.options.connection._lastSessionId === options.connection._lastSessionId
)
}
return instance.name === name
})
return collection && collection.instance
}
Mongo.Collection.getAll = function () {
return instances
}
// Meteor.Collection will lack ownProperties that are added back to Mongo.Collection
Meteor.Collection = Mongo.Collection