MongoDB and Mongoose in NodeJS
MongoDB and Mongoose in NodeJS
Object-document Model
Mongoose Overview
Mongoose Models
Types of properties
Virtual methods
Property validation
Mongoose CRUD operations
Do:
.where({conditionOne: true}).or({conditionTwo: true})
Mongoose Queries (2)
Mongoose supports many queries:
For equality/non-equality
Selection of some properties
Sorting
Limit & skip
All
queries are executed over the object
returned by Model.find*()
Call .exec() at the end to run the query
Mongoose Queries
Live Demo
Mongoose Models Modules
Mongoose Models
http://academy.telerik.com
ASP.NET MVC HTML, SQL, C#, .NET, ASP.NET MVC
SEO - ,
, iPhone, Android, WP7, PhoneGap
, HTML, CSS, JavaScript, Photoshop -
free C# book, C#, Java, C# -
" "
" cloud " C# , ,
Homework
1. Create a modules for Chat, that keep the data into a
local MongoDB instance
The module should have the following functionality:
var chatDb = require('chat-db');
//inserts a new user records into the DB
chatDb.registerUser({user: 'DonchoMinkov', pass: '123456q'});
//inserts a new message record into the DB
//the message has two references to users (from and to)
chatDb.sendMessage({
from: 'DonchoMinkov',
to: 'NikolayKostov',
text: 'Hey, Niki!'
});
//returns an array with all messages between two users
chatDb.getMessages({
with: 'DonchoMinkov',
and: 'NikolayKostov
});