Definitely not comprehensive. This is meant to be a basic memory aid with links to get more details. I'll add to it over time.
$ npm install mongoose --save
const mongoose = require('mongoose');
const uri = process.env.MONGO_URI || 'mongodb://localhost/test';
mongoose.connect(uri, function(err, res) {
...
});
const userSchema = new mongoose.Schema({
name: {
first: String,
last: { type: String, trim: true }
},
age: { type: Number, min: 0 },
posts: [ { title: String, url: String, date: Date } ],
updated: { type: Date, default: Date.now }
});
- String
- Number
- Date
- Buffer
- Boolean
- Mixed
- ObjectId
- Array
SchemaTypes
SchemaType API
SchemaType#default
SchemaType#validate
get
set
select
Mixed types and dates that are modified using JavaScript Date methods are not hooked into mongoose change tracking logic. To save changes, let mongoose know about them using markModified('path')
before calling save
.
A model is a constructor compiled from a schema. Model instances represent documents.
const User = mongoose.model('User', userSchema);
var u = new User({
name: {
first: 'Tony',
last: 'Pujals'
},
age: 99
});
query.$where('this.comments.length > 10 || this.name.length > 5')
// or
query.$where(function() {
return this.comments.length > 10 || this.name.length > 5;
});
http://mongoosejs.com/docs/api.html#query_Query-count
http://mongoosejs.com/docs/api.html#query_Query-distinct
http://mongoosejs.com/docs/api.html#query_Query-elemMatch
http://mongoosejs.com/docs/api.html#query_Query-equals
http://mongoosejs.com/docs/api.html#query_Query-exec
http://mongoosejs.com/docs/api.html#query_Query-exists
http://mongoosejs.com/docs/api.html#query_Query-find
http://mongoosejs.com/docs/api.html#query_Query-findOne
http://mongoosejs.com/docs/api.html#query_Query-findOneAndRemove
http://mongoosejs.com/docs/api.html#query_Query-findOneAndUpdate
http://mongoosejs.com/docs/api.html#query_Query-gt
http://mongoosejs.com/docs/api.html#query_Query-gte
http://mongoosejs.com/docs/api.html#query_Query-hint
http://mongoosejs.com/docs/api.html#query_Query-in
http://mongoosejs.com/docs/api.html#query_Query-lean
http://mongoosejs.com/docs/api.html#query_Query-limit
http://mongoosejs.com/docs/api.html#query_Query-lt
http://mongoosejs.com/docs/api.html#query_Query-lte
http://mongoosejs.com/docs/api.html#query_Query-maxScan
http://mongoosejs.com/docs/api.html#query_Query-merge
http://mongoosejs.com/docs/api.html#query_Query-mod
http://mongoosejs.com/docs/api.html#query_Query-ne
http://mongoosejs.com/docs/api.html#query_Query-nin
http://mongoosejs.com/docs/api.html#query_Query-nor
http://mongoosejs.com/docs/api.html#query_Query-or
http://mongoosejs.com/docs/api.html#query_Query-populate
http://mongoosejs.com/docs/api.html#query_Query-read
http://mongoosejs.com/docs/api.html#query_Query-regex
http://mongoosejs.com/docs/api.html#query_Query-remove
http://mongoosejs.com/docs/api.html#query_Query-select
http://mongoosejs.com/docs/api.html#query_Query-setOptions
http://mongoosejs.com/docs/api.html#query_Query-size
http://mongoosejs.com/docs/api.html#query_Query-skip
http://mongoosejs.com/docs/api.html#query_Query-slice
http://mongoosejs.com/docs/api.html#query_Query-snapshot
http://mongoosejs.com/docs/api.html#query_Query-sort
http://mongoosejs.com/docs/api.html#query_Query-stream
http://mongoosejs.com/docs/api.html#query_Query-tailable
http://mongoosejs.com/docs/api.html#query_Query-toConstructor
Thanks man, i think it will be
better if you just put examples in place of links