Skip to content

Instantly share code, notes, and snippets.

@tmeasday
Created August 3, 2017 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmeasday/f957de6c4c9c7ece790c2897ff2016d6 to your computer and use it in GitHub Desktop.
Save tmeasday/f957de6c4c9c7ece790c2897ff2016d6 to your computer and use it in GitHub Desktop.
/* 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