Mongoose need to be used on schemas basis
var mongoose = require (' mongoose ');
var Schema = Mongoose. Schema;
var Blogschema = New Schema ({
Title:string, Author:string,
Body:string, Comments: [{body:string, date:date}],
Date: {type:date, Default:Date.now},
Hidden:boolean,
Meta: {votes:number, Favs:number}
});
Create a module
var blog = mongoose.model (' blog ', Blogschema);
Managing the form of a database
var db = Mongoose.connect (' mongodb://localhost/test ');
Mongoose Common query statements
Provides find, FindOne, FindByID for document queries
Model.find (Query,fields,options,callback)//fields,options is an optional parameter
Simple query: Model.find ({' Cursor ': 6},function (Err,doc) {})//doc is the statement after the query
Query only the result of the specified key: Model.find ({},{' first ', ' Last '},function (Err,docs) {})//doc is the only one and last key value that contains the document
Model.findone is the same as find but returns only a single document.
Model.findbyid and find are the same, but it only accepts the document's _id as a parameter, returning a single document
Model.findbyid (Obj._id,function (Err,doc) {})
Model.count returns the number of documents that match the criteria
Model.count (Conditions,callback)
Model.remove Deleting a document that matches a condition
Model.remove (Contions,callback)
Model.where queries are more complex when using where
Modle. Where (' age '). GTE (25)
. where (' tags '). in{[' movie ', ' Music ', ' art '}
. Select (' Name ', ' age ', ' tags '}
. Skip (20)
. Limit (10)
. ASC (' age ')
. Slaveok ()
...
Model.update Updating the database
var contions = {name: ' Borne '},
Update = {$inc: {visits:1}},
Options = {Multi:true}
Model.update (Conditions,update,options,callback)
Read Mongoose API Records