Created
August 3, 2017 01:19
-
-
Save tmeasday/f957de6c4c9c7ece790c2897ff2016d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable import/no-extraneous-dependencies */ | |
import { LocalCollection } from 'meteor-standalone-minimongo'; | |
const collections = {}; | |
class Collection { | |
constructor(name) { | |
if (!collections[name]) { | |
collections[name] = new LocalCollection(); | |
} | |
this.collection = collections[name]; | |
} | |
insertOne(...args) { | |
return { | |
insertedId: this.collection.insert(...args), | |
}; | |
} | |
find(...args) { | |
const cursor = this.collection.find(...args); | |
const res = { | |
// XXX: unimplemented, I guess they need to re-do the cursor | |
sort: () => res, | |
limit: () => res, | |
toArray: () => Promise.resolve(cursor.fetch()), | |
}; | |
return res; | |
} | |
findOne(...args) { | |
return Promise.resolve(this.collection.findOne(...args)); | |
} | |
update(...args) { | |
return Promise.resolve(this.collection.update(...args)); | |
} | |
remove(...args) { | |
return Promise.resolve(this.collection.remove(...args)); | |
} | |
} | |
export const MongoDatabase = { | |
collection(name) { | |
return new Collection(name); | |
}, | |
}; | |
export const MongoClient = { | |
connect() { | |
return Promise.resolve(MongoDatabase); | |
}, | |
}; | |
export function ObjectId(str) { | |
return str || Math.random().toString(36); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment