Skip to content

Instantly share code, notes, and snippets.

@mwmaleks
Created November 1, 2013 09:38
Show Gist options
  • Save mwmaleks/7263113 to your computer and use it in GitHub Desktop.
Save mwmaleks/7263113 to your computer and use it in GitHub Desktop.
mongoose to use
/**
* Created by mwmaleks on 31.10.13.
*/
var mongoose = require('mongoose');
console.log('Версия монгус -', mongoose.version );
var db = mongoose.createConnection('mongodb://localhost/learn');
db.on("error", console.error.bind(console, 'connection error:' ));
//db.once("open", function callback () {
// console.log('Connected!')
//});
var UnicornsSchema = mongoose.Schema({
name: {type: String},
dob: {type: Date},
loves: {type: Array},
weight: {type: Number},
gender: {type: String},
vampires: {type: Number}
});
var unicorns = db.model('unicorns', UnicornsSchema );
//unicorns.find({name: 'Leia'}, 'weight', function (err, result) {
// if (err) return handleError(err);
// console.log(result);
//});
var uni = new unicorns({
_id:'000000000000000000000004',
name: 'Lina',
dob: new Date(1993, 5, 3, 11, 53, 0),
loves: ['bananas', 'passion'],
weight: 650,
gender: 'f',
vampires: 12
});
console.log(uni);
uni.save(function () {
});
unicorns.find({$or: [{loves: 'passion' }, {loves: 'bananas'}]}, function (err, result) {
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment