Skip to content

Instantly share code, notes, and snippets.

@edgarbs1998
Created December 31, 2021 04:49
Show Gist options
  • Save edgarbs1998/75342511e9cdf8eb4f6f9cdcffa19c19 to your computer and use it in GitHub Desktop.
Save edgarbs1998/75342511e9cdf8eb4f6f9cdcffa19c19 to your computer and use it in GitHub Desktop.
const { model, Schema, connect } = require("mongoose");
const { MongoMemoryServer } = require("mongodb-memory-server");
interface User {
name: string;
}
const UserSchema = new Schema<User>({
name: { type: String, required: true },
});
export const UserModel = model<User>("User", UserSchema);
async function test() {
const mongod = await MongoMemoryServer.create();
connect(mongod.getUri());
await UserModel.create({ name: "edgar" });
const result = await UserModel.find()
.map((docs: any) => {
return docs;
})
.exec();
console.dir(result);
}
test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment