Show Menu
Cheatography

Mongoose Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Schema

import { Schema } from "mongoose"

const EntitySchema = new Schema({ / definition / })

const Entity              = model("Entity", EntitySchema)

Create

let entity = new Entity({})
unsaved entity
entity.save()
save created or updated entity; return a promise
let entity = Entity.cr­eat­e({})
save entity; return a promise

Update

Entity.up­dat­eOn­e(p­red­icate, updates, options)
update only the first found item by default; return a promise